Comparing version 1.1.3 to 1.2.0
/** Created by ge on 12/4/15. */ | ||
import { BehaviorSubject, ReplaySubject, Observable } from 'rxjs'; | ||
import { BehaviorSubject, Subject, Observable } from 'rxjs'; | ||
import { Action, Thunk, Reducer, Hash, StateActionBundle } from "./interfaces"; | ||
@@ -10,4 +10,4 @@ export declare const INIT_STORE: string; | ||
rootReducer: Reducer; | ||
update$: ReplaySubject<StateActionBundle<TState>>; | ||
action$: BehaviorSubject<Action>; | ||
update$: Subject<StateActionBundle<TState>>; | ||
action$: Subject<Action>; | ||
constructor(rootReducer: Reducer | Hash<Reducer>, initialState?: TState); | ||
@@ -14,0 +14,0 @@ dispatch(action: Action | Thunk): void; |
@@ -36,4 +36,4 @@ "use strict"; | ||
// action$ is a stream for action objects | ||
this.action$ = new rxjs_1.BehaviorSubject(exports.INIT_STORE_ACTION); | ||
this.update$ = new rxjs_1.ReplaySubject(0); | ||
this.action$ = new rxjs_1.Subject(); | ||
this.update$ = new rxjs_1.Subject(); | ||
this.action$ | ||
@@ -46,2 +46,3 @@ .subscribe(function (action) { | ||
}, function (error) { return console.log('dispatcher$ Error: ', error.toString()); }, function () { return console.log('dispatcher$ completed'); }); | ||
this.action$.next(exports.INIT_STORE_ACTION); | ||
} | ||
@@ -48,0 +49,0 @@ Store.prototype.dispatch = function (action) { |
{ | ||
"name": "luna", | ||
"version": "1.1.3", | ||
"version": "1.2.0", | ||
"description": "a reactive redux-like store", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -40,7 +40,6 @@ # Luna, a reactive redux library with built-in support for async action creator and Thunks | ||
the `store$.action$` is a behavior subject for the actions. The store internally subscribes to this stream and executes the reducers on the store state in response to events from this action stream. | ||
the `store$.action$` is a (publish) subject for the actions. The store internally subscribes to this stream and executes the reducers on the store state in response to events from this action stream. Because it is a (publish) subject, it does not trigger event on subscription. It also does not have the `getValue()` method. | ||
The `store$.update$` is a replay subject for `{state, action}` bundle. It receives updated state/action bundle after the action has been applied to the store. This stream is used as a `post-action` hook for middlewares such as [luna-saga](https://github.com/escherpad/luna-saga). | ||
The `store$.update$` is a (publish) subject for `{state, action}` bundle. It receives updated state/action bundle after the action has been applied to the store. This stream is used as a `post-action` hook for middlewares such as [luna-saga](https://github.com/escherpad/luna-saga). Because it is a (publish) subject, it does not trigger event on subscription. It also does not have the `getValue()` method. | ||
## Wanna use Reactive-Extention (Rxjs) and redux in your project, but don't know how? | ||
@@ -47,0 +46,0 @@ |
@@ -44,7 +44,5 @@ /** Created by ge on 3/26/16. */ | ||
var store = new Store<TState>(rootReducer); // does not need to pass in a inital state | ||
var firstAction:TestAction; | ||
store.action$.subscribe(action=> { | ||
firstAction = action; | ||
}); | ||
expect(firstAction).toBe(INIT_STORE_ACTION); | ||
// you can not capture the INIT_STORE action, | ||
// because the <store>.action$ stream is HOT | ||
// and the initialization happens synchronously. | ||
expect(store.value).toEqual({counter: 0, name: ""}); | ||
@@ -74,2 +72,3 @@ | ||
/* an anti-pattern */ | ||
var subscription = store.select('name') | ||
@@ -80,3 +79,6 @@ .subscribe(name=> { | ||
store.dispatch({type: "SET", payload: "Ge Yang"}); | ||
/* the counter increase fires twice, once on subscription, once on update */ | ||
/* the counter increase fires twice, once on subscription, once on update because | ||
* the store is a behavioralSubject. It is equivalent to ReplaySubject with a buffer | ||
* size of 2 in this regard. | ||
* If you want to avoid triggering on subscription, use update$ or action$ */ | ||
expect(store.value).toEqual({counter: 4, name: "Ge Yang"}); | ||
@@ -83,0 +85,0 @@ subscription.unsubscribe(); |
@@ -31,4 +31,4 @@ /** Created by ge on 3/26/16. */ | ||
store$ | ||
.map(store => ({store, action: store$.action$.getValue()})) | ||
.subscribe(state => console.log("test 2: ", state)); | ||
.update$ | ||
.subscribe((_) => console.log("test 2: ", _)); | ||
@@ -46,6 +46,4 @@ }); | ||
store$ | ||
.map(store => { | ||
return {store, action: store$.action$.getValue()}; | ||
}) | ||
.subscribe(state => console.log("test 3: ", state)); | ||
.update$ | ||
.subscribe(_ => console.log("test 3: ", _)); | ||
@@ -65,6 +63,4 @@ testAction$ | ||
store$ | ||
.map(store => { | ||
return {store, action: store$.action$.getValue()}; | ||
}) | ||
.subscribe(state => console.log("test 4: ", state)); | ||
.update$ | ||
.subscribe(_ => console.log("test 4: ", _)); | ||
@@ -71,0 +67,0 @@ testAction$ |
/** Created by ge on 12/4/15. */ | ||
import {BehaviorSubject, ReplaySubject, Observable} from 'rxjs'; | ||
import {BehaviorSubject, Subject, Observable} from 'rxjs'; | ||
import {passOrCombineReducers} from './util/combineReducers'; | ||
@@ -11,4 +11,4 @@ import {Action, Thunk, Reducer, Hash, StateActionBundle} from "./interfaces"; | ||
public rootReducer:Reducer; | ||
public update$:ReplaySubject<StateActionBundle<TState>>; | ||
public action$:BehaviorSubject<Action>; | ||
public update$:Subject<StateActionBundle<TState>>; | ||
public action$:Subject<Action>; | ||
@@ -22,4 +22,4 @@ constructor(rootReducer:Reducer | Hash<Reducer>, | ||
// action$ is a stream for action objects | ||
this.action$ = new BehaviorSubject<Action>(INIT_STORE_ACTION); | ||
this.update$ = new ReplaySubject<StateActionBundle<TState>>(0); | ||
this.action$ = new Subject<Action>(); | ||
this.update$ = new Subject<StateActionBundle<TState>>(); | ||
this.action$ | ||
@@ -37,2 +37,3 @@ .subscribe( | ||
this.action$.next(INIT_STORE_ACTION); | ||
} | ||
@@ -39,0 +40,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48642
280