@@ -5295,9 +5295,9 @@ return /******/ (function(modules) { // webpackBootstrap
52955295 /**
52965296 * The state for the whole cluster
52975297 */
5298- this . __state = Immutable . Map ( { } )
5298+ this . state = Immutable . Map ( { } )
52995299 /**
5300- * Holds a map of id => reactor instance
5300+ * Holds a map of id => store instance
53015301 */
53025302 this . __stores = Immutable . Map ( { } )
53035303
@@ -5306,7 +5306,10 @@ return /******/ (function(modules) { // webpackBootstrap
53065306 * Change observer interface to observe certain keypaths
53075307 * Created after __initialize so it starts with initialState
53085308 */
5309- this . __changeObserver = new ChangeObserver ( this . __state , this . __evaluator )
5309+ this . __changeObserver = new ChangeObserver ( this . state , this . __evaluator )
5310+
5311+ this . __isBatching = false ;
5312+ this . __batchDispatchCount = 0 ;
53105313 }
53115314
53125315 /**
@@ -5315,7 +5318,7 @@ return /******/ (function(modules) { // webpackBootstrap
53155318 * @return {* }
53165319 */
53175320 Object . defineProperty ( Reactor . prototype , "evaluate" , { writable :true , configurable :true , value :function ( keyPathOrGetter ) { "use strict" ;
5318- return this . __evaluator . evaluate ( this . __state , keyPathOrGetter )
5321+ return this . __evaluator . evaluate ( this . state , keyPathOrGetter )
53195322 } } ) ;
53205323
53215324 /**
@@ -5360,43 +5363,26 @@ return /******/ (function(modules) { // webpackBootstrap
53605363 * @param {object|undefined } payload
53615364 */
53625365 Object . defineProperty ( Reactor . prototype , "dispatch" , { writable :true , configurable :true , value :function ( actionType , payload ) { "use strict" ;
5363- var debug = this . debug
5364- var prevState = this . __state
5365-
5366- this . __state = this . __state . withMutations ( function ( state ) {
5367- if ( this . debug ) {
5368- logging . dispatchStart ( actionType , payload )
5369- }
5370-
5371- // let each core handle the message
5372- this . __stores . forEach ( function ( store , id ) {
5373- var currState = state . get ( id )
5374- var newState = store . handle ( currState , actionType , payload )
5366+ var prevState = this . state
5367+ this . state = this . __handleAction ( prevState , actionType , payload )
53755368
5376- if ( debug && newState === undefined ) {
5377- var error = 'Store handler must return a value, did you forget a return statement'
5378- logging . dispatchError ( error )
5379- throw new Error ( error )
5380- }
5381-
5382- state . set ( id , newState )
5383-
5384- if ( this . debug ) {
5385- logging . storeHandled ( id , currState , newState )
5386- }
5387- } . bind ( this ) )
5388-
5389- if ( this . debug ) {
5390- logging . dispatchEnd ( state )
5391- }
5392- } . bind ( this ) )
5393-
5394- // write the new state to the output stream if changed
5395- if ( this . __state !== prevState ) {
5396- this . __changeObserver . notifyObservers ( this . __state )
5369+ if ( this . __isBatching ) {
5370+ this . __batchDispatchCount ++
5371+ } else if ( this . state !== prevState ) {
5372+ this . __notify ( )
53975373 }
53985374 } } ) ;
53995375
5376+ /**
5377+ * Allows batching of dispatches before notifying change observers
5378+ * @param {Function } fn
5379+ */
5380+ Object . defineProperty ( Reactor . prototype , "batch" , { writable :true , configurable :true , value :function ( fn ) { "use strict" ;
5381+ this . __batchStart ( )
5382+ fn ( )
5383+ this . __batchEnd ( )
5384+ } } ) ;
5385+
54005386 /**
54015387 * @deprecated
54025388 * @param {String } id
@@ -5429,10 +5415,10 @@ return /******/ (function(modules) { // webpackBootstrap
54295415 }
54305416
54315417 this . __stores = this . __stores . set ( id , store )
5432- this . __state = this . __state . set ( id , initialState )
5418+ this . state = this . state . set ( id , initialState )
54335419 } . bind ( this ) )
54345420
5435- this . __changeObserver . notifyObservers ( this . __state )
5421+ this . __notify ( )
54365422 } } ) ;
54375423
54385424 /**
@@ -5442,7 +5428,7 @@ return /******/ (function(modules) { // webpackBootstrap
54425428 Object . defineProperty ( Reactor . prototype , "serialize" , { writable :true , configurable :true , value :function ( ) { "use strict" ;
54435429 var serialized = { }
54445430 this . __stores . forEach ( function ( store , id ) {
5445- var storeState = this . __state . get ( id )
5431+ var storeState = this . state . get ( id )
54465432 serialized [ id ] = store . serialize ( storeState )
54475433 } . bind ( this ) )
54485434 return serialized
@@ -5461,18 +5447,18 @@ return /******/ (function(modules) { // webpackBootstrap
54615447 } . bind ( this ) )
54625448 } . bind ( this ) )
54635449
5464- this . __state = this . __state . merge ( stateToLoad )
5465- this . __changeObserver . notifyObservers ( this . __state )
5450+ this . state = this . state . merge ( stateToLoad )
5451+ this . __notify ( )
54665452 } } ) ;
54675453
54685454 /**
54695455 * Resets the state of a reactor and returns back to initial state
54705456 */
54715457 Object . defineProperty ( Reactor . prototype , "reset" , { writable :true , configurable :true , value :function ( ) { "use strict" ;
54725458 var debug = this . debug
5473- var prevState = this . __state
5459+ var prevState = this . state
54745460
5475- this . __state = Immutable . Map ( ) . withMutations ( function ( state ) {
5461+ this . state = Immutable . Map ( ) . withMutations ( function ( state ) {
54765462 this . __stores . forEach ( function ( store , id ) {
54775463 var storeState = prevState . get ( id )
54785464 var resetStoreState = store . handleReset ( storeState )
@@ -5487,7 +5473,70 @@ return /******/ (function(modules) { // webpackBootstrap
54875473 } . bind ( this ) )
54885474
54895475 this . __evaluator . reset ( )
5490- this . __changeObserver . reset ( this . __state )
5476+ this . __changeObserver . reset ( this . state )
5477+ } } ) ;
5478+
5479+ /**
5480+ * Notifies all change observers with the current state
5481+ * @private
5482+ */
5483+ Object . defineProperty ( Reactor . prototype , "__notify" , { writable :true , configurable :true , value :function ( ) { "use strict" ;
5484+ this . __changeObserver . notifyObservers ( this . state )
5485+ } } ) ;
5486+
5487+
5488+ /**
5489+ * Reduces the current state to the new state given actionType / message
5490+ * @param {string } actionType
5491+ * @param {object|undefined } payload
5492+ * @return {Immutable.Map }
5493+ */
5494+ Object . defineProperty ( Reactor . prototype , "__handleAction" , { writable :true , configurable :true , value :function ( state , actionType , payload ) { "use strict" ;
5495+ return state . withMutations ( function ( state ) {
5496+ if ( this . debug ) {
5497+ logging . dispatchStart ( actionType , payload )
5498+ }
5499+
5500+ // let each core handle the message
5501+ this . __stores . forEach ( function ( store , id ) {
5502+ var currState = state . get ( id )
5503+ var newState = store . handle ( currState , actionType , payload )
5504+
5505+ if ( this . debug && newState === undefined ) {
5506+ var error = 'Store handler must return a value, did you forget a return statement'
5507+ logging . dispatchError ( error )
5508+ throw new Error ( error )
5509+ }
5510+
5511+ state . set ( id , newState )
5512+
5513+ if ( this . debug ) {
5514+ logging . storeHandled ( id , currState , newState )
5515+ }
5516+ } . bind ( this ) )
5517+
5518+ if ( this . debug ) {
5519+ logging . dispatchEnd ( state )
5520+ }
5521+ } . bind ( this ) )
5522+ } } ) ;
5523+
5524+ Object . defineProperty ( Reactor . prototype , "__batchStart" , { writable :true , configurable :true , value :function ( ) { "use strict" ;
5525+ if ( this . __isBatching ) {
5526+ throw new Error ( 'Reactor already in batch mode' )
5527+ }
5528+ this . __isBatching = true
5529+ } } ) ;
5530+
5531+ Object . defineProperty ( Reactor . prototype , "__batchEnd" , { writable :true , configurable :true , value :function ( ) { "use strict" ;
5532+ if ( ! this . __isBatching ) {
5533+ throw new Error ( 'Reactor is not in batch mode' )
5534+ }
5535+
5536+ if ( this . __batchDispatchCount > 0 ) {
5537+ this . __notify ( )
5538+ this . __batchDispatchCount = 0
5539+ }
54915540 } } ) ;
54925541
54935542
@@ -5521,7 +5570,7 @@ return /******/ (function(modules) { // webpackBootstrap
55215570 exports . storeHandled = function ( id , before , after ) {
55225571 if ( console . group ) {
55235572 if ( before !== after ) {
5524- console . debug ( 'Core changed: ' + id )
5573+ console . debug ( 'Store ' + id + ' handled action' )
55255574 }
55265575 }
55275576 }
@@ -5852,8 +5901,13 @@ return /******/ (function(modules) { // webpackBootstrap
58525901 }
58535902
58545903 __applyingComputeFn = true
5855- var evaluatedValue = getComputeFn ( keyPathOrGetter ) . apply ( null , args )
5856- __applyingComputeFn = false
5904+ try {
5905+ var evaluatedValue = getComputeFn ( keyPathOrGetter ) . apply ( null , args )
5906+ __applyingComputeFn = false
5907+ } catch ( e ) {
5908+ __applyingComputeFn = false
5909+ throw e
5910+ }
58575911
58585912 this . __cacheValue ( state , keyPathOrGetter , args , evaluatedValue )
58595913
0 commit comments