Comparing version 1.2.2 to 1.3.0
25
index.js
@@ -1,6 +0,6 @@ | ||
"use strict"; | ||
'use strict'; | ||
exports.__esModule = true; | ||
var state = { | ||
__container__: {}, | ||
__container__: {} | ||
}; | ||
@@ -11,6 +11,6 @@ | ||
* @public | ||
* @version 1.2.0 | ||
* @param {object} config | ||
* @version 1.3.0 | ||
* @param {object} config | ||
* @param {string} config.name name state | ||
* @param {any} config.defaultValue default value | ||
* @param {any} config.defaultValue default value | ||
* @param {function} config.willUpdate function for before set state | ||
@@ -24,9 +24,14 @@ * @param {function} config.shouldUpdate function for is need update | ||
Object.defineProperty(state, config.name, { | ||
get: function get() { | ||
get: function get() { | ||
return state.__container__[config.name]; | ||
}, | ||
set: function set(value) { | ||
config.willUpdate && config.willUpdate(state.__container__[config.name], value); | ||
if (config.shouldUpdate) | ||
if (config.shouldUpdate(state.__container__[config.name], value) === false) return; | ||
if ( | ||
config.shouldUpdate(state.__container__[config.name], value) === false | ||
) | ||
return; | ||
config.willUpdate && | ||
config.willUpdate(state.__container__[config.name], value); | ||
state.__container__[config.name] = value; | ||
@@ -36,3 +41,3 @@ config.didUpdate && config.didUpdate(value); | ||
}); | ||
} | ||
}; | ||
@@ -44,2 +49,2 @@ /** | ||
*/ | ||
exports.state = state; | ||
exports.state = state; |
{ | ||
"name": "jetstate", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "state managment", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
4091
42