Comparing version 1.1.0 to 1.1.1
31
index.js
@@ -20,23 +20,16 @@ "use strict"; | ||
exports.init = function init(config) { | ||
var name = config.name; | ||
var defaultValue = config.defaultValue; | ||
var willReceive = config.willReceive; | ||
var willUpdate = config.willUpdate; | ||
var didUpdate = config.didUpdate; | ||
var shouldUpdate = config.shouldUpdate; | ||
state.__container__[name] = defaultValue; | ||
Object.defineProperty(state, name, { | ||
get() { | ||
willReceive && willReceive(state.__container__[name]); | ||
return state.__container__[name]; | ||
state.__container__[config.name] = config.defaultValue; | ||
Object.defineProperty(state, config.name, { | ||
get: function get() { | ||
config.willReceive && config.willReceive(state.__container__[config.name]); | ||
return state.__container__[config.name]; | ||
}, | ||
set(value) { | ||
willUpdate && willUpdate(state.__container__[name], value); | ||
if (shouldUpdate) | ||
if (shouldUpdate(state.__container__[name], value) === false) return; | ||
state.__container__[name] = value; | ||
didUpdate && didUpdate(value); | ||
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; | ||
state.__container__[config.name] = value; | ||
config.didUpdate && config.didUpdate(value); | ||
} | ||
}) | ||
}); | ||
} | ||
@@ -43,0 +36,0 @@ |
{ | ||
"name": "jetstate", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "state managment", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
3247
65