GitHub

  • import { Injectable } from ‘ @angular/core ‘ ; import { Action } from ‘ @ngrx/store ‘ ; import { ActionCreatorFactory } from ‘ ngrx-action-creator-factory ‘ ; @ Injectable () export class NowPlaylistActions { static MEDIA_ENDED = ‘ [NOW PLAYLIST] MEDIA_ENDED ‘ ; static QUEUE = ‘ [NOW PLAYLIST] QUEUE ‘ ; static SELECT = ‘ [NOW PLAYLIST] SELECT ‘ ; // as injectable constructor ( private acf : ActionCreatorFactory ) { this .
  • The factory allows to decalre a minimal action creator declaration with a typed payload for the action creator function and have type support when using this function.
  • Whenever a ts file is changed, it will rerun the tests.
  • npm install ngrx-action-creator-factory –save-dev
  • The service came out as a result of the open source project Echoes Player – an alternative player for watching and listening to media from youtube.

ngrx-action-creator-factory – An Action Creator Factory for ngrx

@JavaScriptKicks: ngrx-action-creator-factory - An Action Creator Factory for ngrx by orizens #javascript #angularjs #rxjs

This is an angular 2 provider based (or a simple class) – read about the concept at Simple Action Creators for ngrx/store in Angular 2.

This service came out as a result of the open source project Echoes Player – an alternative player for watching and listening to media from youtube.

This factory allows to decalre a minimal action creator declaration with a typed payload for the action creator function and have type support when using this function. This also results (in most cases) in a one line declaration.

supports Angular 2 – Final – 2.2.1

MIT

Currently supported:

First, import the ActionCreatorFactory to your module:

import { NgModule } from ‘@angular/core’; import { ActionCreatorFactory } from ‘ngrx-action-creator-factory’; @NgModule({ imports:[ BrowserModule ], providers: [ ActionCreatorFactory ], declarations: [ AppComponent, ], bootstrap: [ AppComponent ] }) export class AppModule { } platformBrowserDynamic().bootstrapModule(AppModule);

Next, use the ngrx-action-creator-factory either as a static factory or as an injectable provider:

import { Injectable } from ‘@angular/core’; import { Action } from ‘@ngrx/store’; import { ActionCreatorFactory } from ‘ngrx-action-creator-factory’; @Injectable() export class NowPlaylistActions { static MEDIA_ENDED = ‘[NOW PLAYLIST] MEDIA_ENDED’; static QUEUE = ‘[NOW PLAYLIST] QUEUE’; static SELECT = ‘[NOW PLAYLIST] SELECT’; // as injectable constructor(private acf : ActionCreatorFactory) { this.queueVideo = this.acf.create(NowPlaylistActions.QUEUE); // This is the same as the above this.queueVideo = this.acf.create(NowPlaylistActions.QUEUE); } // as a static method mediaEnded = ActionCreatorFactory.create(NowPlaylistActions.MEDIA_ENDED); // OR as a static typed method selectMedia = ActionCreatorFactory.create(NowPlaylistActions.SELECT); }

This will: compile ts files, watch for changes and start the test task. Whenever a ts file is changed, it will rerun the tests.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

GitHub

You might also like More from author

Comments are closed, but trackbacks and pingbacks are open.