boxed-state
Advanced tools
Comparing version 0.8.2 to 0.8.4
37
index.js
@@ -11,2 +11,5 @@ "use strict"; | ||
const deleteItems = objEachBreak.deleteItems; | ||
const getBoxOnlyOptions = boxedImmutable.getBoxOnlyOptions; | ||
const UNDEFINED = void 0; | ||
@@ -20,3 +23,3 @@ | ||
if (!this.boxed) { | ||
this.boxed = this.box.withBoxOptions(this.getBoxOnlyOptions, this.getState()); | ||
this.boxed = this.box.withBoxOptions(this.boxOnlyOptions, this.getState()); | ||
} | ||
@@ -26,3 +29,8 @@ return this.boxed; | ||
function saveBoxed() { | ||
/** | ||
* save modified state | ||
* @param onDoneCallback function to call on save complete | ||
* @return {*} | ||
*/ | ||
function saveBoxed(onDoneCallback = UNDEFINED) { | ||
const boxed = this.boxed; | ||
@@ -34,3 +42,3 @@ if (boxed) { | ||
if (this.saveState) { | ||
return this.saveState(modified, boxed); | ||
return this.saveState(modified, boxed, onDoneCallback); | ||
} else { | ||
@@ -40,2 +48,4 @@ throw new TypeError("Save State Not Supported on this instance, saveState callback not provided"); | ||
} | ||
} else if (onDoneCallback) { | ||
onDoneCallback(); | ||
} | ||
@@ -57,2 +67,3 @@ } | ||
function boxOptions(options) { | ||
this.boxOnlyOptions = getBoxOnlyOptions(options); | ||
this.boxed = UNDEFINED; | ||
@@ -65,3 +76,4 @@ return this.proxiedThis; | ||
* @param getState get state callback which returns state to use for boxing | ||
* @param saveState save state callback (boxed.$_modified$, boxed), value returned from this callback is returned to caller of .commit() | ||
* @param saveState save state callback saveState(boxed.$_modified$, boxed, onDoneCallback), | ||
* value returned from this callback is returned to caller of .save(onDoneCallback) | ||
* @param options box or options object | ||
@@ -72,2 +84,5 @@ * if options object: | ||
* cancelBoxedProp: property name to use for cancel, default 'cancel' | ||
* | ||
* + additional box only options for creating the box | ||
* | ||
*/ | ||
@@ -104,9 +119,10 @@ function BoxedState(getState, saveState, options) { | ||
this.saveState = saveState; | ||
this.boxOnlyOptions = getBoxOnlyOptions(options); | ||
this.boxed = UNDEFINED; | ||
this.proxiedThis = UNDEFINED; | ||
this.getBoxed = getBoxed.bind(this); | ||
this.saveBoxed = saveBoxed.bind(this); | ||
this.cancelBoxed = cancelBoxed.bind(this); | ||
this.boxOptions = boxOptions.bind(this); | ||
this.getBoxed = this.getBoxed.bind(this); | ||
this.saveBoxed = this.saveBoxed.bind(this); | ||
this.cancelBoxed = this.cancelBoxed.bind(this); | ||
this.boxOptions = this.boxOptions.bind(this); | ||
} | ||
@@ -199,4 +215,5 @@ | ||
* @param getState callback returning state to box | ||
* @param saveState callback taking (modified, boxed) of the state on .$_save$() | ||
* @param options function for creating box or object containing {box: boxFunction} if not defined then global boxed-immutable.box will be used. | ||
* @param saveState callback taking (modified, boxed, onDoneCallback) of the state on .save(onDoneCallback) | ||
* @param options function for creating box or object containing {box: boxFunction} | ||
* if not defined then global boxed-immutable.box will be used. | ||
* @return proxy which reflects fresh immutable state with commit/cancel on mods. | ||
@@ -203,0 +220,0 @@ */ |
{ | ||
"name": "boxed-state", | ||
"version": "0.8.2", | ||
"version": "0.8.4", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "Immutable proxy wrapper with exception free access to nested properties and auto-instantiation of intermediate containers when nested properties are defined", |
@@ -9,3 +9,3 @@ "use strict"; | ||
const boxOut = require('boxed-out'); | ||
const boxState = require('../index'); | ||
const boxState = require('boxed-state').boxState; | ||
@@ -163,3 +163,3 @@ const box = boxedImmutable.box; | ||
return onDemand || origVal; | ||
}, (modified, boxed) => { | ||
}, (modified, boxed, callback) => { | ||
saveCalled++; | ||
@@ -166,0 +166,0 @@ onDemand = { |
describe(`README`, () => { | ||
test(`readme useage`, () => { | ||
const boxState = require('boxed-state'); | ||
const boxState = require('boxed-state').boxState; | ||
@@ -61,3 +61,3 @@ // your function for returning the current immutable state object | ||
const boxedImmutable = require('boxed-immutable'); | ||
const boxState = require('boxed-state'); | ||
const boxState = require('boxed-state').boxState; | ||
@@ -64,0 +64,0 @@ let dashBoardState = { |
@@ -8,3 +8,3 @@ "use strict"; | ||
const BOXED_GET_THIS = boxedImmutable.BOXED_GET_THIS; | ||
const boxState = require('../index'); | ||
const boxState = require('boxed-state').boxState; | ||
const utilTypeFuncs = require('util-type-funcs'); | ||
@@ -11,0 +11,0 @@ const isObjectLike = utilTypeFuncs.isObjectLike; |
@@ -5,2 +5,3 @@ # Version History | ||
- [0.8.4](#084) | ||
- [0.8.2](#082) | ||
@@ -10,2 +11,9 @@ - [0.8.0](#080) | ||
## 0.8.4 | ||
* Add: `callback` argument to `boxedState.save(callback)` and passed to `saveState` | ||
`function(modified, boxed, callback)` to allow for callback when setting React state to state | ||
update completion callback. | ||
* Add: implement `boxOptions(options)` to change box only options to be used for box creation | ||
## 0.8.2 | ||
@@ -12,0 +20,0 @@ |
45247
951