11import difference from 'lodash/difference' ;
22import union from 'lodash/union' ;
3+ import $$observable from 'symbol-observable' ;
34
45export const ActionTypes = {
56 PERFORM_ACTION : 'PERFORM_ACTION' ,
@@ -383,6 +384,14 @@ function unliftState(liftedState) {
383384function unliftStore ( liftedStore , liftReducer ) {
384385 let lastDefinedState ;
385386
387+ function getState ( ) {
388+ const state = unliftState ( liftedStore . getState ( ) ) ;
389+ if ( state !== undefined ) {
390+ lastDefinedState = state ;
391+ }
392+ return lastDefinedState ;
393+ }
394+
386395 return {
387396 ...liftedStore ,
388397
@@ -393,16 +402,31 @@ function unliftStore(liftedStore, liftReducer) {
393402 return action ;
394403 } ,
395404
396- getState ( ) {
397- const state = unliftState ( liftedStore . getState ( ) ) ;
398- if ( state !== undefined ) {
399- lastDefinedState = state ;
400- }
401- return lastDefinedState ;
402- } ,
405+ getState,
403406
404407 replaceReducer ( nextReducer ) {
405408 liftedStore . replaceReducer ( liftReducer ( nextReducer ) ) ;
409+ } ,
410+
411+ [ $$observable ] ( ) {
412+ return {
413+ ...liftedStore [ $$observable ] ( ) ,
414+ subscribe ( observer ) {
415+ if ( typeof observer !== 'object' ) {
416+ throw new TypeError ( 'Expected the observer to be an object.' ) ;
417+ }
418+
419+ function observeState ( ) {
420+ if ( observer . next ) {
421+ observer . next ( getState ( ) ) ;
422+ }
423+ }
424+
425+ observeState ( ) ;
426+ const unsubscribe = liftedStore . subscribe ( observeState ) ;
427+ return { unsubscribe } ;
428+ }
429+ } ;
406430 }
407431 } ;
408432}
0 commit comments