@@ -108,7 +108,7 @@ return /******/ (function(modules) { // webpackBootstrap
108
108
109
109
/**
110
110
* Returns true if the value is an ImmutableJS data structure
111
- * or a javascript primitive that is immutable (stirng , number, etc)
111
+ * or a JavaScript primitive that is immutable (string , number, etc)
112
112
* @param {* } obj
113
113
* @return {boolean }
114
114
*/
@@ -124,7 +124,7 @@ return /******/ (function(modules) { // webpackBootstrap
124
124
* Can be called on any type
125
125
*/
126
126
function toJS ( arg ) {
127
- // arg instanceof Immutable.Sequence is unreleable
127
+ // arg instanceof Immutable.Sequence is unreliable
128
128
return ( isImmutable ( arg ) )
129
129
? arg . toJS ( )
130
130
: arg
@@ -5100,7 +5100,7 @@ return /******/ (function(modules) { // webpackBootstrap
5100
5100
return objectToString ( val ) === '[object Array]'
5101
5101
}
5102
5102
5103
- // taken from underscore source to account for browser descrepency
5103
+ // taken from underscore source to account for browser discrepancy
5104
5104
/* istanbul ignore if */
5105
5105
if ( typeof / ./ !== 'function' && typeof Int8Array !== 'object' ) {
5106
5106
/**
@@ -5123,7 +5123,7 @@ return /******/ (function(modules) { // webpackBootstrap
5123
5123
}
5124
5124
5125
5125
/**
5126
- * Checks if the passed in value is af type Object
5126
+ * Checks if the passed in value is of type Object
5127
5127
* @param {* } val
5128
5128
* @return {boolean }
5129
5129
*/
@@ -5274,7 +5274,7 @@ return /******/ (function(modules) { // webpackBootstrap
5274
5274
5275
5275
5276
5276
/**
5277
- * In Nuclear Reactors are where state is stored . Reactors
5277
+ * State is stored in NuclearJS Reactors . Reactors
5278
5278
* contain a 'state' object which is an Immutable.Map
5279
5279
*
5280
5280
* The only way Reactors can change state is by reacting to
@@ -5308,8 +5308,13 @@ return /******/ (function(modules) { // webpackBootstrap
5308
5308
*/
5309
5309
this . __changeObserver = new ChangeObserver ( this . state , this . __evaluator )
5310
5310
5311
- this . __isBatching = false ;
5312
- this . __batchDispatchCount = 0 ;
5311
+ // keep track of the depth of batch nesting
5312
+ this . __batchDepth = 0
5313
+ // number of dispatches in the top most batch cycle
5314
+ this . __batchDispatchCount = 0
5315
+
5316
+ // keep track if we are currently dispatching
5317
+ this . __isDispatching = false
5313
5318
}
5314
5319
5315
5320
/**
@@ -5363,13 +5368,36 @@ return /******/ (function(modules) { // webpackBootstrap
5363
5368
* @param {object|undefined } payload
5364
5369
*/
5365
5370
Object . defineProperty ( Reactor . prototype , "dispatch" , { writable :true , configurable :true , value :function ( actionType , payload ) { "use strict" ;
5371
+ if ( this . __batchDepth === 0 ) {
5372
+ if ( this . __isDispatching ) {
5373
+ this . __isDispatching = false
5374
+ throw new Error ( 'Dispatch may not be called while a dispatch is in progress' )
5375
+ }
5376
+ this . __isDispatching = true
5377
+ }
5378
+
5366
5379
var prevState = this . state
5367
- this . state = this . __handleAction ( prevState , actionType , payload )
5368
5380
5369
- if ( this . __isBatching ) {
5381
+ try {
5382
+ this . state = this . __handleAction ( prevState , actionType , payload )
5383
+ } catch ( e ) {
5384
+ this . __isDispatching = false
5385
+ throw e
5386
+ }
5387
+
5388
+
5389
+ if ( this . __batchDepth > 0 ) {
5370
5390
this . __batchDispatchCount ++
5371
- } else if ( this . state !== prevState ) {
5372
- this . __notify ( )
5391
+ } else {
5392
+ if ( this . state !== prevState ) {
5393
+ try {
5394
+ this . __notify ( )
5395
+ } catch ( e ) {
5396
+ this . __isDispatching = false
5397
+ throw e
5398
+ }
5399
+ }
5400
+ this . __isDispatching = false
5373
5401
}
5374
5402
} } ) ;
5375
5403
@@ -5429,7 +5457,10 @@ return /******/ (function(modules) { // webpackBootstrap
5429
5457
var serialized = { }
5430
5458
this . __stores . forEach ( function ( store , id ) {
5431
5459
var storeState = this . state . get ( id )
5432
- serialized [ id ] = store . serialize ( storeState )
5460
+ var serializedState = store . serialize ( storeState )
5461
+ if ( serializedState !== undefined ) {
5462
+ serialized [ id ] = serializedState
5463
+ }
5433
5464
} . bind ( this ) )
5434
5465
return serialized
5435
5466
} } ) ;
@@ -5442,7 +5473,10 @@ return /******/ (function(modules) { // webpackBootstrap
5442
5473
each ( state , function ( serializedStoreState , storeId ) {
5443
5474
var store = this . __stores . get ( storeId )
5444
5475
if ( store ) {
5445
- stateToLoad . set ( storeId , store . deserialize ( serializedStoreState ) )
5476
+ var storeState = store . deserialize ( serializedStoreState )
5477
+ if ( storeState !== undefined ) {
5478
+ stateToLoad . set ( storeId , storeState )
5479
+ }
5446
5480
}
5447
5481
} . bind ( this ) )
5448
5482
} . bind ( this ) )
@@ -5484,7 +5518,6 @@ return /******/ (function(modules) { // webpackBootstrap
5484
5518
this . __changeObserver . notifyObservers ( this . state )
5485
5519
} } ) ;
5486
5520
5487
-
5488
5521
/**
5489
5522
* Reduces the current state to the new state given actionType / message
5490
5523
* @param {string } actionType
@@ -5497,15 +5530,23 @@ return /******/ (function(modules) { // webpackBootstrap
5497
5530
logging . dispatchStart ( actionType , payload )
5498
5531
}
5499
5532
5500
- // let each core handle the message
5533
+ // let each store handle the message
5501
5534
this . __stores . forEach ( function ( store , id ) {
5502
5535
var currState = state . get ( id )
5503
- var newState = store . handle ( currState , actionType , payload )
5536
+ var newState
5537
+
5538
+ try {
5539
+ newState = store . handle ( currState , actionType , payload )
5540
+ } catch ( e ) {
5541
+ // ensure console.group is properly closed
5542
+ logging . dispatchError ( e . message )
5543
+ throw e
5544
+ }
5504
5545
5505
5546
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 )
5547
+ var errorMsg = 'Store handler must return a value, did you forget a return statement'
5548
+ logging . dispatchError ( errorMsg )
5549
+ throw new Error ( errorMsg )
5509
5550
}
5510
5551
5511
5552
state . set ( id , newState )
@@ -5522,19 +5563,24 @@ return /******/ (function(modules) { // webpackBootstrap
5522
5563
} } ) ;
5523
5564
5524
5565
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
5566
+ this . __batchDepth ++
5529
5567
} } ) ;
5530
5568
5531
5569
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 ( )
5570
+ this . __batchDepth --
5571
+
5572
+ if ( this . __batchDepth <= 0 ) {
5573
+ if ( this . __batchDispatchCount > 0 ) {
5574
+ // set to true to catch if dispatch called from observer
5575
+ this . __isDispatching = true
5576
+ try {
5577
+ this . __notify ( )
5578
+ } catch ( e ) {
5579
+ this . __isDispatching = false
5580
+ throw e
5581
+ }
5582
+ this . __isDispatching = false
5583
+ }
5538
5584
this . __batchDispatchCount = 0
5539
5585
}
5540
5586
} } ) ;
@@ -5644,7 +5690,7 @@ return /******/ (function(modules) { // webpackBootstrap
5644
5690
} } ) ;
5645
5691
5646
5692
/**
5647
- * Specify an getter and a change handler fn
5693
+ * Specify a getter and a change handler function
5648
5694
* Handler function is called whenever the value of the getter changes
5649
5695
* @param {Getter } getter
5650
5696
* @param {function } handler
@@ -5900,9 +5946,10 @@ return /******/ (function(modules) { // webpackBootstrap
5900
5946
throw new Error ( 'Evaluate may not be called within a Getters computeFn' )
5901
5947
}
5902
5948
5949
+ var evaluatedValue
5903
5950
__applyingComputeFn = true
5904
5951
try {
5905
- var evaluatedValue = getComputeFn ( keyPathOrGetter ) . apply ( null , args )
5952
+ evaluatedValue = getComputeFn ( keyPathOrGetter ) . apply ( null , args )
5906
5953
__applyingComputeFn = false
5907
5954
} catch ( e ) {
5908
5955
__applyingComputeFn = false
@@ -5962,7 +6009,7 @@ return /******/ (function(modules) { // webpackBootstrap
5962
6009
* @param {Getter }
5963
6010
*/
5964
6011
Object . defineProperty ( Evaluator . prototype , "untrack" , { writable :true , configurable :true , value :function ( getter ) { "use strict" ;
5965
- // TODO: untrack all depedencies
6012
+ // TODO: untrack all dependencies
5966
6013
} } ) ;
5967
6014
5968
6015
Object . defineProperty ( Evaluator . prototype , "reset" , { writable :true , configurable :true , value :function ( ) { "use strict" ;
@@ -6053,7 +6100,7 @@ return /******/ (function(modules) { // webpackBootstrap
6053
6100
}
6054
6101
6055
6102
/**
6056
- * This method is overriden by extending classses to setup message handlers
6103
+ * This method is overridden by extending classes to setup message handlers
6057
6104
* via `this.on` and to set up the initial state
6058
6105
*
6059
6106
* Anything returned from this function will be coerced into an ImmutableJS value
@@ -6086,7 +6133,7 @@ return /******/ (function(modules) { // webpackBootstrap
6086
6133
6087
6134
/**
6088
6135
* Pure function taking the current state of store and returning
6089
- * the new state after a Nuclear reactor has been reset
6136
+ * the new state after a NuclearJS reactor has been reset
6090
6137
*
6091
6138
* Overridable
6092
6139
*/
@@ -6102,23 +6149,23 @@ return /******/ (function(modules) { // webpackBootstrap
6102
6149
} } ) ;
6103
6150
6104
6151
/**
6105
- * Serializes store state to plain JSON serializable javascript
6152
+ * Serializes store state to plain JSON serializable JavaScript
6106
6153
* Overridable
6107
6154
* @param {* }
6108
6155
* @return {* }
6109
6156
*/
6110
6157
Object . defineProperty ( Store . prototype , "serialize" , { writable :true , configurable :true , value :function ( state ) { "use strict" ;
6111
- return toJS ( state ) ;
6158
+ return toJS ( state )
6112
6159
} } ) ;
6113
6160
6114
6161
/**
6115
- * Deserializes plain javascript to store state
6162
+ * Deserializes plain JavaScript to store state
6116
6163
* Overridable
6117
6164
* @param {* }
6118
6165
* @return {* }
6119
6166
*/
6120
6167
Object . defineProperty ( Store . prototype , "deserialize" , { writable :true , configurable :true , value :function ( state ) { "use strict" ;
6121
- return toImmutable ( state ) ;
6168
+ return toImmutable ( state )
6122
6169
} } ) ;
6123
6170
6124
6171
0 commit comments