Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dot-store

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dot-store - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

dist/changed.js

579

dist/index.js

@@ -6,8 +6,4 @@ "use strict";

});
exports.ops = undefined;
exports.opEventRegex = exports.ops = undefined;
var _set = require("babel-runtime/core-js/set");
var _set2 = _interopRequireDefault(_set);
var _extends2 = require("babel-runtime/helpers/extends");

@@ -29,2 +25,6 @@

var _getPrototypeOf = require("babel-runtime/core-js/object/get-prototype-of");
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");

@@ -38,2 +38,14 @@

var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _get2 = require("babel-runtime/helpers/get");
var _get3 = _interopRequireDefault(_get2);
var _inherits2 = require("babel-runtime/helpers/inherits");
var _inherits3 = _interopRequireDefault(_inherits2);
var _dotPropImmutable = require("dot-prop-immutable");

@@ -43,4 +55,8 @@

var _change = require("./change");
var _emitter = require("./emitter");
var _emitter2 = _interopRequireDefault(_emitter);
var _changed = require("./changed");
var _string = require("./string");

@@ -52,5 +68,9 @@

var DotStore = function () {
var opEventRegex = exports.opEventRegex = /(before|after)(Delete|Get|Merge|Set|Toggle|Update)/;
var DotStore = function (_Emitter) {
(0, _inherits3.default)(DotStore, _Emitter);
function DotStore() {
var _this = this;
var _this2 = this;

@@ -60,9 +80,5 @@ var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

this.state = state;
var _this = (0, _possibleConstructorReturn3.default)(this, (DotStore.__proto__ || (0, _getPrototypeOf2.default)(DotStore)).call(this));
this.listeners = {};
this.listenersBy = {
fn: {},
prop: {}
};
_this.state = state;

@@ -94,3 +110,3 @@ var _iteratorNormalCompletion = true;

}
}, _callee, _this);
}, _callee, _this2);
}));

@@ -121,2 +137,4 @@

}
return _this;
}

@@ -136,3 +154,3 @@

value = _ref3.value;
var props, detectChange, payload, result, prevState;
var props, prev, payload, result, prevState;
return _regenerator2.default.wrap(function _callee2$(_context2) {

@@ -143,6 +161,7 @@ while (1) {

props = (0, _string.propToArray)(prop);
detectChange = (0, _change.changeFn)({ props: props });
prev = this.getSync(prop);
payload = {
detectChange: detectChange,
changed: (0, _changed.buildChanged)({ props: props }),
op: op,
prev: prev,
prop: prop,

@@ -154,3 +173,3 @@ props: props,

_context2.next = 5;
return this.dispatch("before", payload);
return this.emitOp("before", payload);

@@ -166,19 +185,17 @@ case 5:

detectChange = (0, _change.changeFn)({
prevState: prevState,
props: props,
state: this.state
});
payload = (0, _extends3.default)({}, payload, {
detectChange: detectChange,
changed: (0, _changed.buildChanged)({
prevState: prevState,
props: props,
state: this.state
}),
prevState: prevState
});
_context2.next = 12;
return this.dispatch("after", payload);
_context2.next = 11;
return this.emitOp("after", payload);
case 12:
case 11:
if (!(op == "get")) {
_context2.next = 16;
_context2.next = 15;
break;

@@ -189,6 +206,6 @@ }

case 16:
case 15:
return _context2.abrupt("return", this.state);
case 17:
case 16:
case "end":

@@ -207,381 +224,269 @@ return _context2.stop();

}()
}, {
key: "emitOp",
value: function () {
var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(event, data) {
var events, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, e;
// Events
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
events = this.events(event, data);
_iteratorNormalCompletion2 = true;
_didIteratorError2 = false;
_iteratorError2 = undefined;
_context3.prev = 4;
_iterator2 = (0, _getIterator3.default)(events);
}, {
key: "addListener",
value: function addListener(_ref4) {
var prop = _ref4.prop,
fn = _ref4.fn,
listener = _ref4.listener;
case 6:
if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) {
_context3.next = 13;
break;
}
this.addListenerBy("fn", fn, listener);
this.addListenerBy("prop", prop, listener);
}
}, {
key: "addListenerBy",
value: function addListenerBy(kind, key, listener) {
if (!key || !listener) {
return;
}
e = _step2.value;
_context3.next = 10;
return this.emitSerial(e, (0, _extends3.default)({}, data, {
state: this.state
}));
var map = this.listenersBy[kind];
case 10:
_iteratorNormalCompletion2 = true;
_context3.next = 6;
break;
map[key] = map[key] || [];
map[key] = map[key].concat([listener]);
}
}, {
key: "removeListener",
value: function removeListener(options) {
var listener = options.listener;
case 13:
_context3.next = 19;
break;
var listeners = [];
case 15:
_context3.prev = 15;
_context3.t0 = _context3["catch"](4);
_didIteratorError2 = true;
_iteratorError2 = _context3.t0;
var _arr = ["fn", "prop"];
for (var _i = 0; _i < _arr.length; _i++) {
var kind = _arr[_i];
var map = this.listenersBy[kind];
var key = options[kind];
case 19:
_context3.prev = 19;
_context3.prev = 20;
map[key] = map[key] || [];
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
if (listener) {
listeners = listeners.concat(map[key].filter(function (fn) {
return fn == listener;
}));
map[key] = map[key].filter(function (fn) {
return fn != listener;
});
} else {
listeners = listeners.concat(map[key]);
map[key] = [];
}
}
case 22:
_context3.prev = 22;
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
if (!_didIteratorError2) {
_context3.next = 25;
break;
}
try {
for (var _iterator2 = (0, _getIterator3.default)(new _set2.default(listeners)), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _listener = _step2.value;
throw _iteratorError2;
this.unsubscribe(_listener);
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
case 25:
return _context3.finish(22);
case 26:
return _context3.finish(19);
case 27:
case "end":
return _context3.stop();
}
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}, _callee3, this, [[4, 15, 19, 27], [20,, 22, 26]]);
}));
function emitOp(_x5, _x6) {
return _ref4.apply(this, arguments);
}
}
return emitOp;
}()
}, {
key: "removeListenerByIntersection",
value: function removeListenerByIntersection(prop, fn) {
var propListeners = this.listenersBy.prop[prop];
var fnListeners = this.listenersBy.fn[fn];
key: "events",
value: function events(event, _ref5) {
var op = _ref5.op;
var listeners = fnListeners.filter(function (f) {
return propListeners.includes(f);
});
var opEvent = "" + event + (0, _string.capitalize)(op);
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = (0, _getIterator3.default)(listeners), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var listener = _step3.value;
this.removeListener({ fn: fn, listener: listener, prop: prop });
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
if (op == "get") {
return [opEvent];
} else {
return [opEvent, event + "Update"];
}
}
}, {
key: "defaultEvent",
value: function defaultEvent(_ref5) {
var event = _ref5.event,
fn = _ref5.fn;
if (typeof event !== "string") {
fn = event;
event = "afterUpdate";
key: "on",
value: function on(event, prop, listener) {
if (!prop && !listener) {
;var _ref6 = ["afterUpdate", undefined, event];
event = _ref6[0];
prop = _ref6[1];
listener = _ref6[2];
} else if (!listener && event.match(opEventRegex)) {
;var _ref7 = [undefined, prop];
prop = _ref7[0];
listener = _ref7[1];
} else if (!listener) {
;var _ref8 = ["afterUpdate", event, prop];
event = _ref8[0];
prop = _ref8[1];
listener = _ref8[2];
}
this.ensureListener(event);
if (prop) {
var customListener = function customListener(options) {
var changed = options.changed;
return { event: event, fn: fn };
var vars = changed(prop);
if (vars) {
return listener((0, _extends3.default)({}, options, vars));
}
};
return (0, _get3.default)(DotStore.prototype.__proto__ || (0, _getPrototypeOf2.default)(DotStore.prototype), "on", this).call(this, event, customListener);
} else {
return (0, _get3.default)(DotStore.prototype.__proto__ || (0, _getPrototypeOf2.default)(DotStore.prototype), "on", this).call(this, event, listener);
}
}
}, {
key: "dispatch",
key: "once",
value: function () {
var _ref6 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(event, payload) {
var _iteratorNormalCompletion4, _didIteratorError4, _iteratorError4, _iterator4, _step4, e, _iteratorNormalCompletion5, _didIteratorError5, _iteratorError5, _iterator5, _step5, fn;
var _ref9 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4(event, prop) {
var _ref10, options, changed, vars;
return _regenerator2.default.wrap(function _callee3$(_context3) {
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context3.prev = _context3.next) {
switch (_context4.prev = _context4.next) {
case 0:
_iteratorNormalCompletion4 = true;
_didIteratorError4 = false;
_iteratorError4 = undefined;
_context3.prev = 3;
_iterator4 = (0, _getIterator3.default)(this.events(event, payload));
if (!prop && !event.match(opEventRegex)) {
;_ref10 = ["afterUpdate", event];
event = _ref10[0];
prop = _ref10[1];
}
case 5:
if (_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done) {
_context3.next = 37;
if (!prop) {
_context4.next = 11;
break;
}
e = _step4.value;
_context4.next = 4;
return (0, _get3.default)(DotStore.prototype.__proto__ || (0, _getPrototypeOf2.default)(DotStore.prototype), "once", this).call(this, event);
this.ensureListener(e);
case 4:
options = _context4.sent;
changed = options.changed;
vars = changed(prop);
_iteratorNormalCompletion5 = true;
_didIteratorError5 = false;
_iteratorError5 = undefined;
_context3.prev = 11;
_iterator5 = (0, _getIterator3.default)(this.listeners[e]);
case 13:
if (_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done) {
_context3.next = 20;
if (!vars) {
_context4.next = 9;
break;
}
fn = _step5.value;
_context3.next = 17;
return fn((0, _extends3.default)({}, payload, { state: this.state }));
return _context4.abrupt("return", (0, _extends3.default)({}, options, vars));
case 17:
_iteratorNormalCompletion5 = true;
_context3.next = 13;
case 9:
_context4.next = 14;
break;
case 20:
_context3.next = 26;
break;
case 11:
_context4.next = 13;
return (0, _get3.default)(DotStore.prototype.__proto__ || (0, _getPrototypeOf2.default)(DotStore.prototype), "once", this).call(this, event);
case 22:
_context3.prev = 22;
_context3.t0 = _context3["catch"](11);
_didIteratorError5 = true;
_iteratorError5 = _context3.t0;
case 13:
return _context4.abrupt("return", _context4.sent);
case 26:
_context3.prev = 26;
_context3.prev = 27;
case 14:
case "end":
return _context4.stop();
}
}
}, _callee4, this);
}));
if (!_iteratorNormalCompletion5 && _iterator5.return) {
_iterator5.return();
}
function once(_x7, _x8) {
return _ref9.apply(this, arguments);
}
case 29:
_context3.prev = 29;
return once;
}()
}, {
key: "oncePresent",
value: function () {
var _ref11 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5(event, prop) {
var _ref12, value;
if (!_didIteratorError5) {
_context3.next = 32;
break;
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
if (!prop && !event.match(opEventRegex)) {
;_ref12 = ["afterUpdate", event];
event = _ref12[0];
prop = _ref12[1];
}
throw _iteratorError5;
case 32:
return _context3.finish(29);
case 33:
return _context3.finish(26);
case 34:
_iteratorNormalCompletion4 = true;
_context3.next = 5;
break;
case 37:
_context3.next = 43;
break;
case 39:
_context3.prev = 39;
_context3.t1 = _context3["catch"](3);
_didIteratorError4 = true;
_iteratorError4 = _context3.t1;
case 43:
_context3.prev = 43;
_context3.prev = 44;
if (!_iteratorNormalCompletion4 && _iterator4.return) {
_iterator4.return();
if (!prop) {
_context5.next = 5;
break;
}
case 46:
_context3.prev = 46;
value = this.getSync(prop);
if (!_didIteratorError4) {
_context3.next = 49;
if (!value) {
_context5.next = 5;
break;
}
throw _iteratorError4;
return _context5.abrupt("return", {
prev: value,
prop: prop,
props: (0, _string.propToArray)(prop),
state: this.state,
store: this,
value: value
});
case 49:
return _context3.finish(46);
case 5:
_context5.next = 7;
return this.once(event, prop);
case 50:
return _context3.finish(43);
case 7:
return _context5.abrupt("return", _context5.sent);
case 51:
return _context3.abrupt("return", this.state);
case 52:
case 8:
case "end":
return _context3.stop();
return _context5.stop();
}
}
}, _callee3, this, [[3, 39, 43, 51], [11, 22, 26, 34], [27,, 29, 33], [44,, 46, 50]]);
}, _callee5, this);
}));
function dispatch(_x5, _x6) {
return _ref6.apply(this, arguments);
function oncePresent(_x9, _x10) {
return _ref11.apply(this, arguments);
}
return dispatch;
return oncePresent;
}()
}, {
key: "ensureListener",
value: function ensureListener(event) {
if (!this.listeners[event]) {
this.listeners[event] = [];
}
}
}, {
key: "events",
value: function events(event, _ref7) {
var op = _ref7.op;
var opEvent = "" + event + (0, _string.capitalize)(op);
if (op == "get") {
return [opEvent];
} else {
return [opEvent, event + "Update"];
}
}
}, {
key: "subscribe",
value: function subscribe(event, fn) {
;
var _defaultEvent = this.defaultEvent({ event: event, fn: fn });
event = _defaultEvent.event;
fn = _defaultEvent.fn;
this.listeners[event].push(fn);
}
}, {
key: "unsubscribe",
value: function unsubscribe(event, fn) {
;
var _defaultEvent2 = this.defaultEvent({ event: event, fn: fn });
event = _defaultEvent2.event;
fn = _defaultEvent2.fn;
if (fn) {
this.listeners[event] = this.listeners[event].filter(function (f) {
return f !== fn;
});
} else {
this.listeners[event] = [];
}
}
}, {
key: "on",
value: function on(prop, fn) {
var _this2 = this;
var once = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var listener = function listener(options) {
var detectChange = options.detectChange;
var vars = detectChange(prop);
if (vars) {
if (once) {
_this2.removeListenerByIntersection(prop, fn);
}
fn((0, _extends3.default)({}, options, vars));
}
};
this.addListener({ fn: fn, listener: listener, prop: prop });
this.subscribe(listener);
return listener;
}
}, {
key: "off",
value: function off(prop, fn) {
if (prop && !fn) {
this.removeListener({ prop: prop });
value: function off(event, listener) {
if (!listener) {
;var _ref13 = ["afterUpdate", event];
event = _ref13[0];
listener = _ref13[1];
} else if (!event.match(opEventRegex)) {
throw new TypeError("off event must be " + opEventRegex);
}
if (prop && fn) {
this.removeListenerByIntersection(prop, fn);
}
(0, _get3.default)(DotStore.prototype.__proto__ || (0, _getPrototypeOf2.default)(DotStore.prototype), "off", this).call(this, event, listener);
}
}, {
key: "once",
value: function once(prop, fn) {
return this.on(prop, fn, true);
}
}, {
key: "oncePresent",
value: function oncePresent(prop, fn) {
var value = this.getSync(prop);
if (value) {
fn({
prop: prop,
props: (0, _string.propToArray)(prop),
state: this.state,
store: this,
value: value
});
} else {
this.once(prop, fn);
}
}
}]);
return DotStore;
}();
}(_emitter2.default);
exports.default = DotStore;
//# sourceMappingURL=index.js.map
{
"name": "dot-store",
"version": "2.0.2",
"version": "2.1.0",
"description": "Like Redux, but easy",

@@ -23,2 +23,3 @@ "keywords": [

"build": "rimraf dist; babel lib --out-dir dist --source-maps",
"emitter": "cp node_modules/emittery/index.js lib/emitter.js",
"fix": "npm run lint -- --fix",

@@ -42,2 +43,3 @@ "prepublishOnly": "npm run build",

"babel-preset-stage-0": "^6.24.1",
"emittery": "^0.3.0",
"fxtr": "1",

@@ -44,0 +46,0 @@ "jest": "22",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc