Comparing version 1.0.5 to 1.1.0
{ | ||
"name": "fun-model", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"description": "fun-model is pure functional implementation of FLUX architecture.", | ||
@@ -25,3 +25,5 @@ "main": "./index.js", | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
"ts-loader": "^0.8.2" | ||
}, | ||
"devDependencies": { | ||
@@ -35,2 +37,2 @@ "gulp": "3.9.0", | ||
"license": "MIT" | ||
} | ||
} |
@@ -11,3 +11,3 @@ import * as s from './store'; | ||
validateRenderCallback(); | ||
if (changeState(unifyCursor(cursor, params), handler, params)) { | ||
if (changeQueuedState(unifyCursor(cursor, params), handler, params)) { | ||
render(); | ||
@@ -28,3 +28,3 @@ d.log('Rendering invoked...'); | ||
let pair = pairs[i]; | ||
if (changeState(pair.cursor, pair.handler, params)) | ||
if (changeQueuedState(pair.cursor, pair.handler, params)) | ||
changed = true; | ||
@@ -41,11 +41,7 @@ } | ||
let c = unifyCursor(cursor, params); | ||
let oldState = s.getState(c); | ||
let newState = handler(oldState, params); | ||
if (oldState !== newState) { | ||
s.setState(c, newState); | ||
d.log('Global state has been changed.'); | ||
if (changeQueuedState(c, handler, params)) { | ||
render(); | ||
d.log('Rendering invoked...'); | ||
} | ||
f(newState); | ||
f(s.getState(c)); | ||
}, 0); | ||
@@ -59,2 +55,18 @@ }); | ||
} | ||
let isStateLocked = false; | ||
let queueOfHandlers = []; | ||
function changeQueuedState(cursor, handler, params) { | ||
if (isStateLocked) { | ||
queueOfHandlers = [{ cursor, handler, params }, ...queueOfHandlers]; | ||
return; | ||
} | ||
isStateLocked = true; | ||
let isStateChanged = changeState(cursor, handler, params); | ||
let n; | ||
while (n = queueOfHandlers.pop()) | ||
isStateChanged = changeState(n.cursor, n.handler, n.params) || isStateChanged; | ||
isStateLocked = false; | ||
isStateChanged && d.log('Global state has been changed.'); | ||
return isStateChanged; | ||
} | ||
function changeState(cursor, handler, params) { | ||
@@ -66,4 +78,3 @@ let oldState = s.getState(cursor); | ||
s.setState(cursor, newState); | ||
d.log('Global state has been changed.'); | ||
return true; | ||
} |
@@ -23,3 +23,3 @@ import * as s from './store'; | ||
validateRenderCallback(); | ||
if (changeState(unifyCursor<TState, TParams>(cursor, params), handler, params)) { | ||
if (changeQueuedState(unifyCursor<TState, TParams>(cursor, params), handler, params)) { | ||
render(); | ||
@@ -47,3 +47,3 @@ d.log('Rendering invoked...'); | ||
let pair = pairs[i]; | ||
if (changeState(pair.cursor, pair.handler, params)) | ||
if (changeQueuedState(pair.cursor, pair.handler, params)) | ||
changed = true; | ||
@@ -62,11 +62,7 @@ } | ||
let c = unifyCursor<TState, TParams>(cursor, params); | ||
let oldState = s.getState(c); | ||
let newState = handler(oldState, params); | ||
if (oldState !== newState) { | ||
s.setState(c, newState); | ||
d.log('Global state has been changed.'); | ||
if (changeQueuedState(c, handler, params)) { | ||
render(); | ||
d.log('Rendering invoked...'); | ||
} | ||
f(newState); | ||
f(s.getState(c)); | ||
}, 0); | ||
@@ -82,2 +78,26 @@ }); | ||
interface IQueuedHandling<TState extends s.IState, TParams> { | ||
cursor: s.ICursor<TState>; | ||
handler: (state: TState, t?: TParams) => TState; | ||
params: TParams; | ||
} | ||
let isStateLocked = false; | ||
let queueOfHandlers: IQueuedHandling<s.IState, Object>[] = []; | ||
function changeQueuedState<TState extends s.IState, TParams>(cursor: s.ICursor<TState>, handler: (state: TState, t?: TParams) => TState, params: TParams) | ||
: boolean { | ||
if (isStateLocked) { | ||
queueOfHandlers = [{ cursor, handler, params }, ...queueOfHandlers]; | ||
return; | ||
} | ||
isStateLocked = true; | ||
let isStateChanged = changeState(cursor, handler, params); | ||
let n; | ||
while (n = queueOfHandlers.pop()) | ||
isStateChanged = changeState(n.cursor, n.handler, n.params) || isStateChanged; | ||
isStateLocked = false; | ||
isStateChanged && d.log('Global state has been changed.'); | ||
return isStateChanged; | ||
} | ||
function changeState<TState extends s.IState, TParams>(cursor: s.ICursor<TState>, handler: (state: TState, t?: TParams) => TState, params: TParams) | ||
@@ -90,4 +110,3 @@ : boolean { | ||
s.setState(cursor, newState); | ||
d.log('Global state has been changed.'); | ||
return true; | ||
} |
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
173030
23
399
1
+ Addedts-loader@^0.8.2
+ Addedarrify@1.0.1(transitive)
+ Addedbig.js@3.2.0(transitive)
+ Addedcolors@1.4.0(transitive)
+ Addedemojis-list@2.1.0(transitive)
+ Addedenhanced-resolve@0.9.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedjson5@0.5.1(transitive)
+ Addedloader-utils@0.2.17(transitive)
+ Addedmemory-fs@0.2.0(transitive)
+ Addedobject-assign@2.1.14.1.1(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedtapable@0.1.10(transitive)
+ Addedts-loader@0.8.2(transitive)