Comparing version 0.2.0 to 0.3.0
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.mutations = undefined; | ||
exports.ops = undefined; | ||
@@ -19,2 +19,4 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _string = require("./string"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -24,3 +26,3 @@ | ||
const mutations = exports.mutations = ["delete", "merge", "set", "toggle"]; | ||
const ops = exports.ops = ["delete", "get", "merge", "set", "toggle"]; | ||
@@ -34,6 +36,6 @@ class DotStore { | ||
for (let op of mutations) { | ||
for (let op of ops) { | ||
this[op] = (() => { | ||
var _ref = _asyncToGenerator(function* (prop, value) { | ||
return yield _this.update({ op, prop, value }); | ||
return yield _this.store({ op, prop, value }); | ||
}); | ||
@@ -59,10 +61,12 @@ | ||
dispatch(event, { op, prop, state, value }) { | ||
dispatch(event, payload) { | ||
var _this2 = this; | ||
return _asyncToGenerator(function* () { | ||
_this2.ensureListener(event); | ||
for (let e of _this2.events(event, payload)) { | ||
_this2.ensureListener(e); | ||
for (let fn of _this2.listeners[event]) { | ||
yield fn({ op, prop, state, value }); | ||
for (let fn of _this2.listeners[e]) { | ||
yield fn(payload); | ||
} | ||
} | ||
@@ -80,18 +84,28 @@ | ||
get(props) { | ||
events(event, { op }) { | ||
let opEvent = `${event}${(0, _string.capitalize)(op)}`; | ||
if (op == "get") { | ||
return [opEvent]; | ||
} else { | ||
return [opEvent, `${event}Update`]; | ||
} | ||
} | ||
getSync(props) { | ||
return _camelDotPropImmutable2.default.get(this.state, props); | ||
} | ||
update({ op, prop, value }) { | ||
store({ op, prop: ogProp, value }) { | ||
var _this3 = this; | ||
return _asyncToGenerator(function* () { | ||
let { prop: resolvedProp } = _camelDotPropImmutable2.default.camelDotMatch({ | ||
let { prop } = _camelDotPropImmutable2.default.camelDotMatch({ | ||
obj: _this3.state, | ||
prop | ||
prop: ogProp | ||
}); | ||
let event = { | ||
let payload = { | ||
op, | ||
prop: resolvedProp, | ||
prop, | ||
state: _this3.state, | ||
@@ -101,10 +115,22 @@ value | ||
yield _this3.dispatch("beforeUpdate", event); | ||
yield _this3.dispatch("before", payload); | ||
let state = _dotPropImmutable2.default[op](_this3.state, resolvedProp, value); | ||
_this3.state = state; | ||
let result = _dotPropImmutable2.default[op](_this3.state, prop, value); | ||
let state; | ||
event = _extends({}, event, { state }); | ||
if (op == "get") { | ||
state = _this3.state; | ||
} else { | ||
_this3.state = state = result; | ||
} | ||
return yield _this3.dispatch("afterUpdate", event); | ||
payload = _extends({}, payload, { state }); | ||
yield _this3.dispatch("after", payload); | ||
if (op == "get") { | ||
return result; | ||
} else { | ||
return _this3.state; | ||
} | ||
})(); | ||
@@ -111,0 +137,0 @@ } |
{ | ||
"name": "dot-store", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Like Redux, but easy", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
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
11000
5
115