rx-flux
rx-flux is state manager inspired by flux
Last updated 2 years ago by litealex .
Original npm · Tarball · package.json
$ cnpm install rx-flux 
SYNC missed versions from official npm registry.

rx-flux

rx-flux is state manager inspired by flux

npm version

Features

  • One immutable state
  • Simple action for state updateting
  • Support Angular routing resolvers
  • Access for store by obervables

Instalation

npm install -S rx-flux

Getting started

Step 1: Import RxFluxModule

import { RxFluxModule } from 'rx-flux';

@NgModule({
...
  imports: [
    ...,
    RxFluxModule
  ]
...
})
export class AppModule { }

Step 2: Describe apllication state interface

export interface IApplicationState {
  title?: string
}

Step 3: Import StateManagerService and init state

import { StateManagerService } from 'rx-flux';

...
constructor(private state: StateManagerService<IApplicationState>) {
}
...
ngOnInit() {
  this.state.initState({});
}
...

Step 4: Subscribe on state

export class AppComponent {
  title$ = this.state.listen(x => x.title);
}

// or

export class AppComponent {
  title$ = this.state.chain().safeGet('title').asObservable();
}

Step 5: Update state

this.state.update((prevState, delta) => {
        return {
          ...prevState,
          title: delta
        };
      }, 'Hello');

// or

this.state.chain().safeGet('title').safeSet('Hello');

Resolver example

export interface IAboutState {
	text: string;
	name: string;
}
@Injectable()
export class AboutResolverService extends StateResolver<IAboutState> {
  constructor(protected stateManager: StateManagerService<IAboutState>) {
    super(stateManager);
  }
  nextState(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Partial<IAboutState> {
    return {
      text: 'Helo',
      name: of('Alexander')
    }
  }
}

RouterModule.forChild([{
	path: '',
	component: AboutComponent,
	resolve: {
		state: AboutResolverService
	}
}])
export class AboutComponent implements OnInit {

  
  constructor(private state: StateManagerService<IAboutState>) { 

  }
  text$:Observable<string> = this.state.chain().safeGet('text').asObservable();
  name$:Observable<string>  = this.state.chain().safeGet('name').asObservable();

  ngOnInit() {
  }

}

Current Tags

  • 4.0.1                                ...           latest (2 years ago)

27 Versions

  • 4.0.1                                ...           2 years ago
  • 4.0.0                                ...           2 years ago
  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.0.5                                ...           2 years ago
  • 2.0.4                                ...           2 years ago
  • 2.0.3                                ...           2 years ago
  • 2.0.2                                ...           2 years ago
  • 2.0.1                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.5.0                                ...           2 years ago
  • 1.4.4                                ...           2 years ago
  • 1.4.3                                ...           2 years ago
  • 1.4.2                                ...           2 years ago
  • 1.4.1                                ...           2 years ago
  • 1.4.0                                ...           2 years ago
  • 1.3.2                                ...           2 years ago
  • 1.3.1                                ...           2 years ago
  • 1.3.0                                ...           2 years ago
  • 1.2.2                                ...           2 years ago
  • 1.2.1                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 54
Dependencies (1)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |