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 1.1.7 to 2.0.0

dist/change.js

588

dist/index.js

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

});
exports.mutations = undefined;
exports.ops = undefined;
var _camelDotPropImmutable = require("camel-dot-prop-immutable");
var _set = require("babel-runtime/core-js/set");
var _camelDotPropImmutable2 = _interopRequireDefault(_camelDotPropImmutable);
var _set2 = _interopRequireDefault(_set);
var _extends2 = require("babel-runtime/helpers/extends");
var _extends3 = _interopRequireDefault(_extends2);
var _regenerator = require("babel-runtime/regenerator");
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require("babel-runtime/helpers/asyncToGenerator");
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
var _getIterator2 = require("babel-runtime/core-js/get-iterator");
var _getIterator3 = _interopRequireDefault(_getIterator2);
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require("babel-runtime/helpers/createClass");
var _createClass3 = _interopRequireDefault(_createClass2);
var _dotPropImmutable = require("dot-prop-immutable");

@@ -17,94 +41,534 @@

var _change = require("./change");
var _string = require("./string");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
var ops = exports.ops = ["delete", "get", "merge", "set", "toggle"];
const mutations = exports.mutations = ["delete", "merge", "set", "toggle"];
class DotStore {
constructor(state = {}) {
var DotStore = function () {
function DotStore() {
var _this = this;
this.listeners = {};
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
(0, _classCallCheck3.default)(this, DotStore);
this.state = state;
for (let op of mutations) {
this[op] = (() => {
var _ref = _asyncToGenerator(function* (prop, value) {
return yield _this.mutate(op, prop, value);
});
this.listeners = {};
this.listenersBy = {
fn: {},
prop: {}
};
return function (_x, _x2) {
return _ref.apply(this, arguments);
};
})();
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
var _loop = function _loop() {
var op = _step.value;
_this[op] = function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(prop, value) {
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return _this.store({ op: op, prop: prop, value: value });
case 2:
return _context.abrupt("return", _context.sent);
case 3:
case "end":
return _context.stop();
}
}
}, _callee, _this);
}));
return function (_x2, _x3) {
return _ref.apply(this, arguments);
};
}();
};
for (var _iterator = (0, _getIterator3.default)(ops), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
_loop();
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
defaultEvent(event, fn) {
if (typeof event !== "string") {
fn = event;
event = "afterMutate";
(0, _createClass3.default)(DotStore, [{
key: "getSync",
value: function getSync(prop) {
return _dotPropImmutable2.default.get(this.state, prop);
}
}, {
key: "store",
value: function () {
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(_ref3) {
var op = _ref3.op,
prop = _ref3.prop,
value = _ref3.value;
var props, detectChange, payload, result, prevState;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
props = (0, _string.propToArray)(prop);
detectChange = (0, _change.changeFn)({ props: props });
payload = {
detectChange: detectChange,
op: op,
prop: prop,
props: props,
store: this,
value: value
};
_context2.next = 5;
return this.dispatch("before", payload);
this.ensureListener(event);
case 5:
result = _dotPropImmutable2.default[op](this.state, prop, value);
prevState = this.state;
return { event, fn };
}
dispatch(event, prop, state) {
var _this2 = this;
if (op != "get") {
this.state = result;
}
return _asyncToGenerator(function* () {
_this2.ensureListener(event);
detectChange = (0, _change.changeFn)({
prevState: prevState,
props: props,
state: this.state
});
for (let fn of _this2.listeners[event]) {
yield fn(prop, state);
payload = (0, _extends3.default)({}, payload, {
detectChange: detectChange,
prevState: prevState
});
_context2.next = 12;
return this.dispatch("after", payload);
case 12:
if (!(op == "get")) {
_context2.next = 16;
break;
}
return _context2.abrupt("return", result);
case 16:
return _context2.abrupt("return", this.state);
case 17:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
function store(_x4) {
return _ref2.apply(this, arguments);
}
return _this2.state;
})();
}
return store;
}()
ensureListener(event) {
if (!this.listeners[event]) {
this.listeners[event] = [];
// Events
}, {
key: "addListener",
value: function addListener(_ref4) {
var prop = _ref4.prop,
fn = _ref4.fn,
listener = _ref4.listener;
this.addListenerBy("fn", fn, listener);
this.addListenerBy("prop", prop, listener);
}
}
}, {
key: "addListenerBy",
value: function addListenerBy(kind, key, listener) {
if (!key || !listener) {
return;
}
get(props) {
return _camelDotPropImmutable2.default.get(this.state, props);
}
var map = this.listenersBy[kind];
mutate(op, prop, value) {
var _this3 = this;
map[key] = map[key] || [];
map[key] = map[key].concat([listener]);
}
}, {
key: "removeListener",
value: function removeListener(options) {
var listener = options.listener;
return _asyncToGenerator(function* () {
let { prop: resolvedProp } = _camelDotPropImmutable2.default.camelDotMatch({
obj: _this3.state,
prop
var listeners = [];
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];
map[key] = map[key] || [];
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] = [];
}
}
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = (0, _getIterator3.default)(new _set2.default(listeners)), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _listener = _step2.value;
this.unsubscribe(_listener);
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
}
}, {
key: "removeListenerByIntersection",
value: function removeListenerByIntersection(prop, fn) {
var propListeners = this.listenersBy.prop[prop];
var fnListeners = this.listenersBy.fn[fn];
var listeners = fnListeners.filter(function (f) {
return propListeners.includes(f);
});
yield _this3.dispatch("beforeMutate", resolvedProp);
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
let state = _dotPropImmutable2.default[op](_this3.state, resolvedProp, value);
_this3.state = state;
try {
for (var _iterator3 = (0, _getIterator3.default)(listeners), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var listener = _step3.value;
return yield _this3.dispatch("afterMutate", resolvedProp, state);
})();
}
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;
}
}
}
}
}, {
key: "defaultEvent",
value: function defaultEvent(_ref5) {
var event = _ref5.event,
fn = _ref5.fn;
subscribe(event, fn) {
;({ event, fn } = this.defaultEvent(event, fn));
if (typeof event !== "string") {
fn = event;
event = "afterUpdate";
}
this.listeners[event].push(fn);
}
this.ensureListener(event);
unsubscribe(event, fn) {
;({ event, fn } = this.defaultEvent(event, fn));
return { event: event, fn: fn };
}
}, {
key: "dispatch",
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;
this.listeners[event] = this.listeners[event].filter(f => f !== fn);
}
}
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_iteratorNormalCompletion4 = true;
_didIteratorError4 = false;
_iteratorError4 = undefined;
_context3.prev = 3;
_iterator4 = (0, _getIterator3.default)(this.events(event, payload));
case 5:
if (_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done) {
_context3.next = 37;
break;
}
e = _step4.value;
this.ensureListener(e);
_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;
break;
}
fn = _step5.value;
_context3.next = 17;
return fn((0, _extends3.default)({}, payload, { state: this.state }));
case 17:
_iteratorNormalCompletion5 = true;
_context3.next = 13;
break;
case 20:
_context3.next = 26;
break;
case 22:
_context3.prev = 22;
_context3.t0 = _context3["catch"](11);
_didIteratorError5 = true;
_iteratorError5 = _context3.t0;
case 26:
_context3.prev = 26;
_context3.prev = 27;
if (!_iteratorNormalCompletion5 && _iterator5.return) {
_iterator5.return();
}
case 29:
_context3.prev = 29;
if (!_didIteratorError5) {
_context3.next = 32;
break;
}
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();
}
case 46:
_context3.prev = 46;
if (!_didIteratorError4) {
_context3.next = 49;
break;
}
throw _iteratorError4;
case 49:
return _context3.finish(46);
case 50:
return _context3.finish(43);
case 51:
return _context3.abrupt("return", this.state);
case 52:
case "end":
return _context3.stop();
}
}
}, _callee3, this, [[3, 39, 43, 51], [11, 22, 26, 34], [27,, 29, 33], [44,, 46, 50]]);
}));
function dispatch(_x5, _x6) {
return _ref6.apply(this, arguments);
}
return dispatch;
}()
}, {
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) {
if (once) {
_this2.removeListenerByIntersection(prop, fn);
}
var detectChange = options.detectChange;
if (detectChange(prop)) {
fn(options);
}
};
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 });
}
if (prop && fn) {
this.removeListenerByIntersection(prop, fn);
}
}
}, {
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;
}();
exports.default = DotStore;
//# sourceMappingURL=index.js.map

137

package.json
{
"name": "dot-store",
"version": "1.1.7",
"version": "2.0.0",
"description": "Like Redux, but easy",

@@ -22,12 +22,4 @@ "keywords": [

"scripts": {
"build":
"rimraf dist; babel lib --out-dir dist --source-maps",
"build": "rimraf dist; babel lib --out-dir dist --source-maps",
"fix": "npm run lint -- --fix",
"lerna-bootstrap": "lerna bootstrap",
"lerna-build": "lerna run build",
"lerna-fix": "lerna run fix",
"lerna-pretty": "lerna run pretty",
"lerna-publish": "lerna publish",
"lerna-lint": "lerna run lint",
"lerna-test": "lerna run test",
"prepublishOnly": "npm run build",

@@ -37,116 +29,31 @@ "pretest": "npm run build",

"lint": "eslint --ignore-path .gitignore --ext=js .",
"test": "jest && npm run lerna-test"
"test": "jest"
},
"dependencies": {
"babel-runtime": "^6.26.0",
"dot-prop-immutable": "^1.4.0"
},
"devDependencies": {
"babel-cli": "6",
"babel-core": "6",
"babel-eslint": "8",
"babel-plugin-transform-async-to-generator": "6",
"babel-plugin-transform-object-rest-spread": "6",
"babel-preset-node6": "11",
"eslint": "4",
"eslint-config-prettier": "2",
"eslint-plugin-prettier": "2",
"eslint-plugin-react": "7",
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.3",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"fxtr": "1",
"husky": "^0.15.0-rc.3",
"jest": "22",
"lerna": "2",
"lint-staged": "6",
"prettier": "1",
"rimraf": "^2.6.2"
"rimraf": "2"
},
"dependencies": {
"camel-dot-prop-immutable": "1"
},
"babel": {
"presets": ["node6"],
"plugins": [
"transform-async-to-generator",
"transform-object-rest-spread"
]
},
"eslintConfig": {
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:prettier/recommended",
"plugin:react/recommended"
"jest": {
"roots": [
"<rootDir>/test/"
],
"parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true
},
"ecmaVersion": 8,
"sourceType": "module"
},
"rules": {
"curly": "error",
"indent": ["error", 2],
"linebreak-style": ["error", "unix"],
"max-len": [
"error",
{
"code": 60,
"ignoreRegExpLiterals": true,
"ignoreStrings": true
}
],
"no-console": [
"error",
{
"allow": ["warn", "error"]
}
],
"quotes": ["error", "double"],
"react/display-name": "off",
"react/no-find-dom-node": "off",
"react/prop-types": "off",
"react/react-in-jsx-scope": "off",
"semi": ["error", "never"],
"sort-keys": [
"error",
"asc",
{
"caseSensitive": true,
"natural": false
}
],
"sort-vars": [
"error",
{
"ignoreCase": true
}
],
"strict": 0
}
},
"husky": {
"hooks": {
"pre-commit": "lint-staged && npm test"
}
},
"jest": {
"roots": ["<rootDir>/test/"],
"setupFiles": ["./test/setup.js"],
"testMatch": ["**/*Test.js"],
"setupFiles": [
"./test/setup.js"
],
"testMatch": [
"**/*Test.js"
],
"verbose": true
},
"lint-staged": {
"*.{css,json,md}": ["prettier --write", "git add"],
"*.js": [
"eslint --ignore-path .gitignore --fix",
"git add"
]
},
"prettier": {
"printWidth": 60,
"semi": false,
"trailingComma": "es5"
}
}

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