Giter VIP home page Giter VIP logo

rxjs-toolkit's People

Contributors

jsonberry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rxjs-toolkit's Issues

Create a strict mode for pick

  • I'm submitting a ...
    [x] feature request

  • Summary
    Basically do the same thing for pick as could be done for hasProps, see #8 for details

Create a strict mode for hasProps

  • I'm submitting a ...
    [x] feature request

  • Summary
    It's possible that a property exists and it's value could be nullable (null or undefined). The developer might not want to consider a nullable value as a valid property, so if there was a strict mode for hasProps then it could throw if a value checked was nullable.

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)
    Not sure of what the syntax would look like, here are some ideas:

source$.pipe(
  hasProps('strict', 'foo', 'bar.baz'), // option 1
  hasProps('foo', 'bar.baz')({strict: true}), // option 2
  hasProps('strict', ['foo', 'bar.baz']), // option 3
)

Some of these could utilize TypeScript function overloads https://www.typescriptlang.org/docs/handbook/functions.html#overloads

I like the idea of option 1 because we could destructure and do some logic from there, though there's probably a better way:

export function hasProps<T>(...args: string[]) {
  const [first, ...rest] = args;
  const propsToCheck = first === 'strict' ? rest : [first, ...rest];

  // no example of rest of the implementation here, just the idea about destructuring

  return (source$: Observable<T>) =>
    source$.pipe(
      mergeMap((signal: T) =>
        hasPropsGuard(signal, propsToCheck)
          ? of(signal)
          : throwError(new Error(hasPropsErrorMessage))
      )
    );
}

Allow for nested prop gets in pick

  • I'm submitting a ...
    [x ] feature request

  • Summary
    pick can take a period delimited string and map that to a nested property

example:

const source$ = of({
  foo: 'foo',
  bar: {
    baz: 'baz',
  }
})

source$.pipe(
  pick('foo', 'baz.baz')
).subscribe(x => console.log(x)) // {foo: 'foo', baz: 'baz'}

By default the nested prop name could be the last level of the branch, so in this example baz.

There could be an optional name for it using {[key: string]: string} syntax:

source$.pipe(
  pick('foo', {far: 'baz.baz'})
).subscribe(x => console.log(x)) // {foo: 'foo', far: 'baz'}

Issues when used with earlier TS versions

  • I'm submitting a ...
    [x] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    When used in an angular project using Angular @ v 6.0.1, rxjs 6.3.3, and TS at ~2.7.2, there are significant errors thrown after installing rxjs-toolkit and the project does not load.

Forgot to grab the error when I saw it... documenting here to try and keep track of the known issue.

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)
    Will try to upgrade the project, but that's not a sufficient solution.

Create delayedActionCollection operator

  • I'm submitting a ...
    [ ] bug report
    [x] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    Create a delayedActionCollection like this:

export function delayedActionsCollection(actionDelayTuple: ActionDelayTuple[]) {
  const ret = actionDelayTuple.map(([action, delayAmount]) =>
    of(action).pipe(delay(delayAmount)),
  );
  return concat(...ret);
}

used like this:

        switchMap((d: HttpResponse<any>) =>
          delayedActionsCollection([
            [new fromToastActions.SuccessToast('Success!'), 2000],
            [new fromToastActions.HideToast(), 5000],
            [new fromMockAPIActions.ResponseSuccess(d), 0],
          ]),
        ),

Create ignoreFalsySignals

import { filter } from 'rxjs/operators';
import { Observable } from 'rxjs';

export const ignoreFalsySignals = () => <T>(source$: Observable<T>) =>
  source$.pipe(filter<T>(signal => !!signal));

Create propsAreTruthy helpers

Create this helper:

import { get } from 'lodash';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

export const propsAreTruthy = (...args: string[]) => <T>(
  source$: Observable<T>,
) =>
  source$.pipe(
    map(signal => {
      for (const arg of args) {
        if (!!!get(signal, arg)) {
          return false;
        }
      }

      return signal;
    }),
  );

Add return signatures to operators

  • I'm submitting a ...
    [x] feature request

  • Summary
    The operators do not have return signatures, adding them will help make it more obvious to what they do in the API docs, and beyond.

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)
    Example:

export const pick<T, R> = (...args: string[]): Observable<R> => map((value: T) => _pick(value, args));

Export operators only

  • I'm submitting a ...
    [ ] bug report
    [x] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

Change main index to export operators only

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.