Skip to content
Tim edited this page Feb 24, 2018 · 7 revisions

@aph5nt you are not thinking reactive enough

onClick$ = new Subject();

constructor(private _store: Store) { this.onClick$ .withLatestFrom(this._store) .subscribe(([data, state]) => { // do whatever you want here }); } <button (click)="onClick$.next({ foo: 'bar', baz: $event })">click common use-case for this is when you map these handlers to ngrx actions, merge them and subscribe them to your store, which means that clicking button will essentially dispatch an action to the store, see #173 (comment)>

https://github.com/ngrx/store/issues/296#issuecomment-291780143

/_ Best practice is to provide the user as part of the payload as mentioned instead of selecting it from the state in the effect. This keeps the Effect pure and easier to test. You can also write a selector that composes the two pieces of data together for your action. https://github.com/ngrx/platform/issues/496#issuecomment-337781385 _/

https://github.com/piotrwitek/react-redux-typescript-guide/blob/master/README.md#state-with-type-level-immutability

@ngrx/store Ignore first emitted value

If you are not interested in the first emitted value, you should be able to use the skip operator:

store.select(...).skip(1)...

https://stackoverflow.com/questions/38953506/ngrx-store-ignore-first-emitted-value

Partial

const values: Partial<FirestoreDoc> = {
  id: reference.key != null ? reference.key : ""
};

Promise

https://basarat.gitbooks.io/typescript/docs/promise.html

function doAsyncTask() {
  var promise = new Promise((resolve, reject) => {
    setTimeout(() => {
      console.log("Async Work Complete");
      if (error) {
        reject();
      } else {
        resolve();
      }
    }, 1000);
  });
  return promise;
}

Conditional Operator (?)

Also known as the ternary operator

Test ? expr1 : expr2;
  • Test: Conditional expression
  • expr1: Value returned if the condition is true
  • expr2: Value returned if the condition is false
 id: reference.key != null ? reference.key : '',

aa bb cc

Clone this wiki locally