Comparing version 2.5.0 to 2.5.1
# Changelog | ||
## v2.5.1 | ||
* Fixing issue related to monkey not firing the correct events ([@roark](https://github.com/roark)). | ||
## v2.5.0 | ||
@@ -4,0 +8,0 @@ |
@@ -1,25 +0,9 @@ | ||
/** | ||
* Baobab Data Structure | ||
* ====================== | ||
* | ||
* A handy data tree with cursors. | ||
*/ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _get = function get(_x3, _x4, _x5) { var _again = true; _function: while (_again) { var object = _x3, property = _x4, receiver = _x5; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x3 = parent; _x4 = property; _x5 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _emmett = require('emmett'); | ||
@@ -51,16 +35,33 @@ | ||
var arrayFrom = helpers.arrayFrom; | ||
var coercePath = helpers.coercePath; | ||
var deepFreeze = helpers.deepFreeze; | ||
var getIn = helpers.getIn; | ||
var makeError = helpers.makeError; | ||
var deepClone = helpers.deepClone; | ||
var deepMerge = helpers.deepMerge; | ||
var shallowClone = helpers.shallowClone; | ||
var shallowMerge = helpers.shallowMerge; | ||
var uniqid = helpers.uniqid; | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** | ||
* Baobab Data Structure | ||
* ====================== | ||
* | ||
* A handy data tree with cursors. | ||
*/ | ||
var arrayFrom = helpers.arrayFrom, | ||
coercePath = helpers.coercePath, | ||
deepFreeze = helpers.deepFreeze, | ||
getIn = helpers.getIn, | ||
makeError = helpers.makeError, | ||
deepClone = helpers.deepClone, | ||
deepMerge = helpers.deepMerge, | ||
shallowClone = helpers.shallowClone, | ||
shallowMerge = helpers.shallowMerge, | ||
hashPath = helpers.hashPath; | ||
/** | ||
* Baobab defaults | ||
*/ | ||
var DEFAULTS = { | ||
@@ -97,17 +98,2 @@ | ||
/** | ||
* Function returning a string hash from a non-dynamic path expressed as an | ||
* array. | ||
* | ||
* @param {array} path - The path to hash. | ||
* @return {string} string - The resultant hash. | ||
*/ | ||
function hashPath(path) { | ||
return 'λ' + path.map(function (step) { | ||
if (_type2['default']['function'](step) || _type2['default'].object(step)) return '#' + uniqid() + '#'; | ||
return step; | ||
}).join('λ'); | ||
} | ||
/** | ||
* Baobab class | ||
@@ -128,43 +114,41 @@ * | ||
var Baobab = (function (_Emitter) { | ||
var Baobab = function (_Emitter) { | ||
_inherits(Baobab, _Emitter); | ||
function Baobab(initialData, opts) { | ||
var _this = this; | ||
_classCallCheck(this, Baobab); | ||
_get(Object.getPrototypeOf(Baobab.prototype), 'constructor', this).call(this); | ||
// Setting initialData to an empty object if no data is provided by use | ||
var _this = _possibleConstructorReturn(this, (Baobab.__proto__ || Object.getPrototypeOf(Baobab)).call(this)); | ||
// Setting initialData to an empty object if no data is provided by use | ||
if (arguments.length < 1) initialData = {}; | ||
// Checking whether given initial data is valid | ||
if (!_type2['default'].object(initialData) && !_type2['default'].array(initialData)) throw makeError('Baobab: invalid data.', { data: initialData }); | ||
if (!_type2.default.object(initialData) && !_type2.default.array(initialData)) throw makeError('Baobab: invalid data.', { data: initialData }); | ||
// Merging given options with defaults | ||
this.options = shallowMerge({}, DEFAULTS, opts); | ||
_this.options = shallowMerge({}, DEFAULTS, opts); | ||
// Disabling immutability & persistence if persistence if disabled | ||
if (!this.options.persistent) { | ||
this.options.immutable = false; | ||
this.options.pure = false; | ||
if (!_this.options.persistent) { | ||
_this.options.immutable = false; | ||
_this.options.pure = false; | ||
} | ||
// Privates | ||
this._identity = '[object Baobab]'; | ||
this._cursors = {}; | ||
this._future = null; | ||
this._transaction = []; | ||
this._affectedPathsIndex = {}; | ||
this._monkeys = {}; | ||
this._previousData = null; | ||
this._data = initialData; | ||
_this._identity = '[object Baobab]'; | ||
_this._cursors = {}; | ||
_this._future = null; | ||
_this._transaction = []; | ||
_this._affectedPathsIndex = {}; | ||
_this._monkeys = {}; | ||
_this._previousData = null; | ||
_this._data = initialData; | ||
// Properties | ||
this.root = new _cursor2['default'](this, [], 'λ'); | ||
delete this.root.release; | ||
_this.root = new _cursor2.default(_this, [], 'λ'); | ||
delete _this.root.release; | ||
// Does the user want an immutable tree? | ||
if (this.options.immutable) deepFreeze(this._data); | ||
if (_this.options.immutable) deepFreeze(_this._data); | ||
@@ -175,3 +159,3 @@ // Bootstrapping root cursor's getters and setters | ||
var r = this.root[name].apply(this.root, arguments); | ||
return r instanceof _cursor2['default'] ? this : r; | ||
return r instanceof _cursor2.default ? this : r; | ||
}; | ||
@@ -183,17 +167,14 @@ }; | ||
// Registering the initial monkeys | ||
if (this.options.monkeyBusiness) { | ||
this._refreshMonkeys(); | ||
if (_this.options.monkeyBusiness) { | ||
_this._refreshMonkeys(); | ||
} | ||
// Initial validation | ||
var validationError = this.validate(); | ||
var validationError = _this.validate(); | ||
if (validationError) throw Error('Baobab: invalid data.', { error: validationError }); | ||
return _this; | ||
} | ||
/** | ||
* Monkey helper. | ||
*/ | ||
/** | ||
* Internal method used to refresh the tree's monkey register on every | ||
@@ -210,2 +191,3 @@ * update. | ||
_createClass(Baobab, [{ | ||
@@ -217,7 +199,7 @@ key: '_refreshMonkeys', | ||
var clean = function clean(data) { | ||
var p = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
var p = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
if (data instanceof _monkey.Monkey) { | ||
data.release(); | ||
(0, _update3['default'])(_this2._monkeys, p, { type: 'unset' }, { | ||
(0, _update3.default)(_this2._monkeys, p, { type: 'unset' }, { | ||
immutable: false, | ||
@@ -231,3 +213,3 @@ persistent: false, | ||
if (_type2['default'].object(data)) { | ||
if (_type2.default.object(data)) { | ||
for (var k in data) { | ||
@@ -240,4 +222,5 @@ clean(data[k], p.concat(k)); | ||
var walk = function walk(data) { | ||
var p = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
var p = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
// Should we sit a monkey in the tree? | ||
@@ -247,3 +230,3 @@ if (data instanceof _monkey.MonkeyDefinition || data instanceof _monkey.Monkey) { | ||
(0, _update3['default'])(_this2._monkeys, p, { type: 'set', value: monkeyInstance }, { | ||
(0, _update3.default)(_this2._monkeys, p, { type: 'set', value: monkeyInstance }, { | ||
immutable: false, | ||
@@ -258,3 +241,3 @@ persistent: false, | ||
// Object iteration | ||
if (_type2['default'].object(data)) { | ||
if (_type2.default.object(data)) { | ||
for (var k in data) { | ||
@@ -289,9 +272,11 @@ walk(data[k], p.concat(k)); | ||
*/ | ||
}, { | ||
key: 'validate', | ||
value: function validate(affectedPaths) { | ||
var _options = this.options; | ||
var validate = _options.validate; | ||
var behavior = _options.validationBehavior; | ||
var _options = this.options, | ||
validate = _options.validate, | ||
behavior = _options.validationBehavior; | ||
if (typeof validate !== 'function') return null; | ||
@@ -330,2 +315,3 @@ | ||
*/ | ||
}, { | ||
@@ -342,3 +328,3 @@ key: 'select', | ||
// Checking that given path is valid | ||
if (!_type2['default'].path(path)) throw makeError('Baobab.select: invalid path.', { path: path }); | ||
if (!_type2.default.path(path)) throw makeError('Baobab.select: invalid path.', { path: path }); | ||
@@ -357,3 +343,3 @@ // Casting to array | ||
if (!cursor) { | ||
cursor = new _cursor2['default'](this, path, hash); | ||
cursor = new _cursor2.default(this, path, hash); | ||
this._cursors[hash] = cursor; | ||
@@ -377,2 +363,3 @@ } | ||
*/ | ||
}, { | ||
@@ -386,12 +373,13 @@ key: 'update', | ||
if (!_type2['default'].operationType(operation.type)) throw makeError('Baobab.update: unknown operation type "' + operation.type + '".', { operation: operation }); | ||
if (!_type2.default.operationType(operation.type)) throw makeError('Baobab.update: unknown operation type "' + operation.type + '".', { operation: operation }); | ||
// Solving the given path | ||
var _getIn = getIn(this._data, path); | ||
var _getIn = getIn(this._data, path), | ||
solvedPath = _getIn.solvedPath, | ||
exists = _getIn.exists; | ||
var solvedPath = _getIn.solvedPath; | ||
var exists = _getIn.exists; | ||
// If we couldn't solve the path, we throw | ||
// If we couldn't solve the path, we throw | ||
if (!solvedPath) throw makeError('Baobab.update: could not solve the given path.', { | ||
@@ -402,3 +390,3 @@ path: solvedPath | ||
// Read-only path? | ||
var monkeyPath = _type2['default'].monkeyPath(this._monkeys, solvedPath); | ||
var monkeyPath = _type2.default.monkeyPath(this._monkeys, solvedPath); | ||
if (monkeyPath && solvedPath.length > monkeyPath.length) throw makeError('Baobab.update: attempting to update a read-only path.', { | ||
@@ -416,3 +404,3 @@ path: solvedPath | ||
if (_type2['default'].object(monkeysNode)) { | ||
if (_type2.default.object(monkeysNode)) { | ||
@@ -433,8 +421,9 @@ // Cloning the operation not to create weird behavior for the user | ||
// Applying the operation | ||
var result = (0, _update3['default'])(this._data, solvedPath, realOperation, this.options); | ||
var result = (0, _update3.default)(this._data, solvedPath, realOperation, this.options); | ||
var data = result.data; | ||
var node = result.node; | ||
var data = result.data, | ||
node = result.node; | ||
// If because of purity, the update was moot, we stop here | ||
if (!('data' in result)) return node; | ||
@@ -483,2 +472,3 @@ | ||
*/ | ||
}, { | ||
@@ -528,2 +518,3 @@ key: 'commit', | ||
*/ | ||
}, { | ||
@@ -548,6 +539,7 @@ key: 'getMonkey', | ||
*/ | ||
}, { | ||
key: 'watch', | ||
value: function watch(mapping) { | ||
return new _watcher2['default'](this, mapping); | ||
return new _watcher2.default(this, mapping); | ||
} | ||
@@ -558,6 +550,7 @@ | ||
*/ | ||
}, { | ||
key: 'release', | ||
value: function release() { | ||
var k = undefined; | ||
var k = void 0; | ||
@@ -575,4 +568,5 @@ this.emit('release'); | ||
// Releasing cursors | ||
for (k in this._cursors) this._cursors[k].release(); | ||
delete this._cursors; | ||
for (k in this._cursors) { | ||
this._cursors[k].release(); | ||
}delete this._cursors; | ||
@@ -588,2 +582,3 @@ // Killing event emitter | ||
*/ | ||
}, { | ||
@@ -600,2 +595,3 @@ key: 'toJSON', | ||
*/ | ||
}, { | ||
@@ -609,5 +605,10 @@ key: 'toString', | ||
return Baobab; | ||
})(_emmett2['default']); | ||
}(_emmett2.default); | ||
exports['default'] = Baobab; | ||
/** | ||
* Monkey helper. | ||
*/ | ||
exports.default = Baobab; | ||
Baobab.monkey = function () { | ||
@@ -629,6 +630,6 @@ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
*/ | ||
Baobab.Cursor = _cursor2['default']; | ||
Baobab.Cursor = _cursor2.default; | ||
Baobab.MonkeyDefinition = _monkey.MonkeyDefinition; | ||
Baobab.Monkey = _monkey.Monkey; | ||
Baobab.type = _type2['default']; | ||
Baobab.type = _type2.default; | ||
Baobab.helpers = helpers; | ||
@@ -639,3 +640,2 @@ | ||
*/ | ||
Baobab.VERSION = '2.5.0'; | ||
module.exports = exports['default']; | ||
Baobab.VERSION = '2.5.0'; |
@@ -1,23 +0,9 @@ | ||
/** | ||
* Baobab Cursors | ||
* =============== | ||
* | ||
* Cursors created by selecting some data within a Baobab tree. | ||
*/ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _get = function get(_x3, _x4, _x5) { var _again = true; _function: while (_again) { var object = _x3, property = _x4, receiver = _x5; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x3 = parent; _x4 = property; _x5 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _emmett = require('emmett'); | ||
@@ -35,2 +21,16 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** | ||
* Baobab Cursors | ||
* =============== | ||
* | ||
* Cursors created by selecting some data within a Baobab tree. | ||
*/ | ||
/** | ||
@@ -56,26 +56,24 @@ * Traversal helper function for dynamic cursors. Will throw a legible error | ||
var Cursor = (function (_Emitter) { | ||
var Cursor = function (_Emitter) { | ||
_inherits(Cursor, _Emitter); | ||
function Cursor(tree, path, hash) { | ||
var _this = this; | ||
_classCallCheck(this, Cursor); | ||
_get(Object.getPrototypeOf(Cursor.prototype), 'constructor', this).call(this); | ||
// If no path were to be provided, we fallback to an empty path (root) | ||
var _this = _possibleConstructorReturn(this, (Cursor.__proto__ || Object.getPrototypeOf(Cursor)).call(this)); | ||
// If no path were to be provided, we fallback to an empty path (root) | ||
path = path || []; | ||
// Privates | ||
this._identity = '[object Cursor]'; | ||
this._archive = null; | ||
_this._identity = '[object Cursor]'; | ||
_this._archive = null; | ||
// Properties | ||
this.tree = tree; | ||
this.path = path; | ||
this.hash = hash; | ||
_this.tree = tree; | ||
_this.path = path; | ||
_this.hash = hash; | ||
// State | ||
this.state = { | ||
_this.state = { | ||
killed: false, | ||
@@ -87,8 +85,8 @@ recording: false, | ||
// Checking whether the given path is dynamic or not | ||
this._dynamicPath = _type2['default'].dynamicPath(this.path); | ||
_this._dynamicPath = _type2.default.dynamicPath(_this.path); | ||
// Checking whether the given path will meet a monkey | ||
this._monkeyPath = _type2['default'].monkeyPath(this.tree._monkeys, this.path); | ||
_this._monkeyPath = _type2.default.monkeyPath(_this.tree._monkeys, _this.path); | ||
if (!this._dynamicPath) this.solvedPath = this.path;else this.solvedPath = (0, _helpers.getIn)(this.tree._data, this.path).solvedPath; | ||
if (!_this._dynamicPath) _this.solvedPath = _this.path;else _this.solvedPath = (0, _helpers.getIn)(_this.tree._data, _this.path).solvedPath; | ||
@@ -101,3 +99,3 @@ /** | ||
*/ | ||
this._writeHandler = function (_ref) { | ||
_this._writeHandler = function (_ref) { | ||
var data = _ref.data; | ||
@@ -122,18 +120,10 @@ | ||
var eventData = Object.defineProperties({}, { | ||
previousData: { | ||
get: function get() { | ||
return (0, _helpers.getIn)(previousData, self.solvedPath).data; | ||
}, | ||
configurable: true, | ||
enumerable: true | ||
var eventData = { | ||
get previousData() { | ||
return (0, _helpers.getIn)(previousData, self.solvedPath).data; | ||
}, | ||
currentData: { | ||
get: function get() { | ||
return self.get(); | ||
}, | ||
configurable: true, | ||
enumerable: true | ||
get currentData() { | ||
return self.get(); | ||
} | ||
}); | ||
}; | ||
@@ -157,10 +147,10 @@ if (_this.state.recording && !_this.state.undoing) _this.archive.add(eventData.previousData); | ||
*/ | ||
this._updateHandler = function (event) { | ||
_this._updateHandler = function (event) { | ||
if (_this.state.killed) return; | ||
var _event$data = event.data; | ||
var paths = _event$data.paths; | ||
var previousData = _event$data.previousData; | ||
var update = fireUpdate.bind(_this, previousData); | ||
var comparedPaths = _this._getComparedPaths(); | ||
var _event$data = event.data, | ||
paths = _event$data.paths, | ||
previousData = _event$data.previousData, | ||
update = fireUpdate.bind(_this, previousData), | ||
comparedPaths = _this._getComparedPaths(); | ||
@@ -172,3 +162,3 @@ if ((0, _helpers.solveUpdate)(paths, comparedPaths)) return update(); | ||
var bound = false; | ||
this._lazyBind = function () { | ||
_this._lazyBind = function () { | ||
if (bound) return; | ||
@@ -184,21 +174,14 @@ | ||
// If the path is dynamic, we actually need to listen to the tree | ||
if (this._dynamicPath) { | ||
this._lazyBind(); | ||
if (_this._dynamicPath) { | ||
_this._lazyBind(); | ||
} else { | ||
// Overriding the emitter `on` and `once` methods | ||
this.on = (0, _helpers.before)(this._lazyBind, this.on.bind(this)); | ||
this.once = (0, _helpers.before)(this._lazyBind, this.once.bind(this)); | ||
_this.on = (0, _helpers.before)(_this._lazyBind, _this.on.bind(_this)); | ||
_this.once = (0, _helpers.before)(_this._lazyBind, _this.once.bind(_this)); | ||
} | ||
return _this; | ||
} | ||
/** | ||
* Method used to allow iterating over cursors containing list-type data. | ||
* | ||
* e.g. for(let i of cursor) { ... } | ||
* | ||
* @returns {object} - Each item sequentially. | ||
*/ | ||
/** | ||
* Internal helpers | ||
@@ -215,2 +198,3 @@ * ----------------- | ||
_createClass(Cursor, [{ | ||
@@ -236,2 +220,3 @@ key: '_getComparedPaths', | ||
*/ | ||
}, { | ||
@@ -248,6 +233,7 @@ key: 'isRoot', | ||
*/ | ||
}, { | ||
key: 'isLeaf', | ||
value: function isLeaf() { | ||
return _type2['default'].primitive(this._get().data); | ||
return _type2.default.primitive(this._get().data); | ||
} | ||
@@ -260,2 +246,3 @@ | ||
*/ | ||
}, { | ||
@@ -277,2 +264,3 @@ key: 'isBranch', | ||
*/ | ||
}, { | ||
@@ -295,2 +283,3 @@ key: 'root', | ||
*/ | ||
}, { | ||
@@ -310,2 +299,3 @@ key: 'select', | ||
*/ | ||
}, { | ||
@@ -324,2 +314,3 @@ key: 'up', | ||
*/ | ||
}, { | ||
@@ -341,2 +332,3 @@ key: 'down', | ||
*/ | ||
}, { | ||
@@ -360,2 +352,3 @@ key: 'left', | ||
*/ | ||
}, { | ||
@@ -381,2 +374,3 @@ key: 'right', | ||
*/ | ||
}, { | ||
@@ -400,2 +394,3 @@ key: 'leftmost', | ||
*/ | ||
}, { | ||
@@ -422,2 +417,3 @@ key: 'rightmost', | ||
*/ | ||
}, { | ||
@@ -431,3 +427,3 @@ key: 'map', | ||
if (!_type2['default'].array(array)) throw Error('baobab.Cursor.map: cannot map a non-list type.'); | ||
if (!_type2.default.array(array)) throw Error('baobab.Cursor.map: cannot map a non-list type.'); | ||
@@ -454,9 +450,11 @@ return array.map(function (item, i) { | ||
*/ | ||
}, { | ||
key: '_get', | ||
value: function _get() { | ||
var path = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; | ||
var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
if (!_type2['default'].path(path)) throw (0, _helpers.makeError)('Baobab.Cursor.getters: invalid path.', { path: path }); | ||
if (!_type2.default.path(path)) throw (0, _helpers.makeError)('Baobab.Cursor.getters: invalid path.', { path: path }); | ||
if (!this.solvedPath) return { data: undefined, solvedPath: null, exists: false }; | ||
@@ -479,2 +477,3 @@ | ||
*/ | ||
}, { | ||
@@ -503,2 +502,3 @@ key: 'exists', | ||
*/ | ||
}, { | ||
@@ -511,8 +511,9 @@ key: 'get', | ||
var _get2 = this._get(path); | ||
var _get2 = this._get(path), | ||
data = _get2.data, | ||
solvedPath = _get2.solvedPath; | ||
var data = _get2.data; | ||
var solvedPath = _get2.solvedPath; | ||
// Emitting the event | ||
// Emitting the event | ||
this.tree.emit('get', { data: data, solvedPath: solvedPath, path: this.path.concat(path) }); | ||
@@ -534,2 +535,3 @@ | ||
*/ | ||
}, { | ||
@@ -554,2 +556,3 @@ key: 'clone', | ||
*/ | ||
}, { | ||
@@ -578,2 +581,3 @@ key: 'deepClone', | ||
*/ | ||
}, { | ||
@@ -586,3 +590,3 @@ key: 'serialize', | ||
if (!_type2['default'].path(path)) throw (0, _helpers.makeError)('Baobab.Cursor.getters: invalid path.', { path: path }); | ||
if (!_type2.default.path(path)) throw (0, _helpers.makeError)('Baobab.Cursor.getters: invalid path.', { path: path }); | ||
@@ -597,3 +601,3 @@ if (!this.solvedPath) return undefined; | ||
var dropComputedData = function dropComputedData(d, m) { | ||
if (!_type2['default'].object(m) || !_type2['default'].object(d)) return; | ||
if (!_type2.default.object(m) || !_type2.default.object(d)) return; | ||
@@ -615,6 +619,7 @@ for (var k in m) { | ||
*/ | ||
}, { | ||
key: 'project', | ||
value: function project(projection) { | ||
if (_type2['default'].object(projection)) { | ||
if (_type2.default.object(projection)) { | ||
var data = {}; | ||
@@ -625,8 +630,8 @@ | ||
}return data; | ||
} else if (_type2['default'].array(projection)) { | ||
var data = []; | ||
} else if (_type2.default.array(projection)) { | ||
var _data = []; | ||
for (var i = 0, l = projection.length; i < l; i++) { | ||
data.push(this.get(projection[i])); | ||
}return data; | ||
_data.push(this.get(projection[i])); | ||
}return _data; | ||
} | ||
@@ -650,2 +655,3 @@ | ||
*/ | ||
}, { | ||
@@ -676,2 +682,3 @@ key: 'startRecording', | ||
*/ | ||
}, { | ||
@@ -690,6 +697,7 @@ key: 'stopRecording', | ||
*/ | ||
}, { | ||
key: 'undo', | ||
value: function undo() { | ||
var steps = arguments.length <= 0 || arguments[0] === undefined ? 1 : arguments[0]; | ||
var steps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; | ||
@@ -713,2 +721,3 @@ if (!this.state.recording) throw new Error('Baobab.Cursor.undo: cursor is not recording.'); | ||
*/ | ||
}, { | ||
@@ -725,2 +734,3 @@ key: 'hasHistory', | ||
*/ | ||
}, { | ||
@@ -737,2 +747,3 @@ key: 'getHistory', | ||
*/ | ||
}, { | ||
@@ -753,2 +764,3 @@ key: 'clearHistory', | ||
*/ | ||
}, { | ||
@@ -787,2 +799,3 @@ key: 'release', | ||
*/ | ||
}, { | ||
@@ -799,2 +812,3 @@ key: 'toJSON', | ||
*/ | ||
}, { | ||
@@ -808,5 +822,14 @@ key: 'toString', | ||
return Cursor; | ||
})(_emmett2['default']); | ||
}(_emmett2.default); | ||
exports['default'] = Cursor; | ||
/** | ||
* Method used to allow iterating over cursors containing list-type data. | ||
* | ||
* e.g. for(let i of cursor) { ... } | ||
* | ||
* @returns {object} - Each item sequentially. | ||
*/ | ||
exports.default = Cursor; | ||
if (typeof Symbol === 'function' && typeof Symbol.iterator !== 'undefined') { | ||
@@ -816,3 +839,3 @@ Cursor.prototype[Symbol.iterator] = function () { | ||
if (!_type2['default'].array(array)) throw Error('baobab.Cursor.@@iterate: cannot iterate a non-list type.'); | ||
if (!_type2.default.array(array)) throw Error('baobab.Cursor.@@iterate: cannot iterate a non-list type.'); | ||
@@ -897,3 +920,3 @@ var i = 0; | ||
// Checking the path's validity | ||
if (!_type2['default'].path(path)) throw (0, _helpers.makeError)('Baobab.Cursor.' + name + ': invalid path.', { path: path }); | ||
if (!_type2.default.path(path)) throw (0, _helpers.makeError)('Baobab.Cursor.' + name + ': invalid path.', { path: path }); | ||
@@ -921,11 +944,10 @@ // Checking the value's validity | ||
makeSetter('unset'); | ||
makeSetter('apply', _type2['default']['function']); | ||
makeSetter('apply', _type2.default.function); | ||
makeSetter('push'); | ||
makeSetter('concat', _type2['default'].array); | ||
makeSetter('concat', _type2.default.array); | ||
makeSetter('unshift'); | ||
makeSetter('pop'); | ||
makeSetter('shift'); | ||
makeSetter('splice', _type2['default'].splicer); | ||
makeSetter('merge', _type2['default'].object); | ||
makeSetter('deepMerge', _type2['default'].object); | ||
module.exports = exports['default']; | ||
makeSetter('splice', _type2.default.splicer); | ||
makeSetter('merge', _type2.default.object); | ||
makeSetter('deepMerge', _type2.default.object); |
@@ -1,3 +0,12 @@ | ||
/* eslint eqeqeq: 0 */ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.uniqid = exports.deepMerge = exports.shallowMerge = exports.deepFreeze = exports.freeze = exports.deepClone = exports.shallowClone = exports.Archive = undefined; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /* eslint eqeqeq: 0 */ | ||
/* eslint no-use-before-define: 0 */ | ||
/** | ||
@@ -9,10 +18,4 @@ * Baobab Helpers | ||
*/ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
exports.arrayFrom = arrayFrom; | ||
@@ -23,2 +26,3 @@ exports.before = before; | ||
exports.makeError = makeError; | ||
exports.hashPath = hashPath; | ||
exports.solveRelativePath = solveRelativePath; | ||
@@ -28,6 +32,2 @@ exports.solveUpdate = solveUpdate; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _monkey = require('./monkey'); | ||
@@ -39,9 +39,8 @@ | ||
/** | ||
* Noop function | ||
*/ | ||
var noop = Function.prototype; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var hasOwnProp = ({}).hasOwnProperty; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var hasOwnProp = {}.hasOwnProperty; | ||
/** | ||
@@ -56,4 +55,4 @@ * Function returning the index of the first element of a list matching the | ||
function index(a, fn) { | ||
var i = undefined, | ||
l = undefined; | ||
var i = void 0, | ||
l = void 0; | ||
for (i = 0, l = a.length; i < l; i++) { | ||
@@ -74,8 +73,8 @@ if (fn(a[i])) return i; | ||
var i = undefined, | ||
l = undefined; | ||
var i = void 0, | ||
l = void 0; | ||
for (i = 0, l = array.length; i < l; i++) newArray[i] = array[i]; | ||
return newArray; | ||
for (i = 0, l = array.length; i < l; i++) { | ||
newArray[i] = array[i]; | ||
}return newArray; | ||
} | ||
@@ -90,3 +89,3 @@ | ||
var Archive = (function () { | ||
var Archive = exports.Archive = function () { | ||
function Archive(size) { | ||
@@ -100,10 +99,2 @@ _classCallCheck(this, Archive); | ||
/** | ||
* Function creating a real array from what should be an array but is not. | ||
* I'm looking at you nasty `arguments`... | ||
* | ||
* @param {mixed} culprit - The culprit to convert. | ||
* @return {array} - The real array. | ||
*/ | ||
/** | ||
* Method retrieving the records. | ||
@@ -114,2 +105,3 @@ * | ||
_createClass(Archive, [{ | ||
@@ -127,2 +119,3 @@ key: 'get', | ||
*/ | ||
}, { | ||
@@ -144,2 +137,3 @@ key: 'add', | ||
*/ | ||
}, { | ||
@@ -158,2 +152,3 @@ key: 'clear', | ||
*/ | ||
}, { | ||
@@ -170,6 +165,13 @@ key: 'back', | ||
return Archive; | ||
})(); | ||
}(); | ||
exports.Archive = Archive; | ||
/** | ||
* Function creating a real array from what should be an array but is not. | ||
* I'm looking at you nasty `arguments`... | ||
* | ||
* @param {mixed} culprit - The culprit to convert. | ||
* @return {array} - The real array. | ||
*/ | ||
function arrayFrom(culprit) { | ||
@@ -187,3 +189,2 @@ return slice(culprit); | ||
*/ | ||
function before(decorator, fn) { | ||
@@ -227,14 +228,12 @@ return function () { | ||
function cloner(deep, item) { | ||
if (!item || typeof item !== 'object' || item instanceof Error || item instanceof _monkey.MonkeyDefinition || item instanceof _monkey.Monkey || 'ArrayBuffer' in global && item instanceof ArrayBuffer) return item; | ||
if (!item || (typeof item === 'undefined' ? 'undefined' : _typeof(item)) !== 'object' || item instanceof Error || item instanceof _monkey.MonkeyDefinition || item instanceof _monkey.Monkey || 'ArrayBuffer' in global && item instanceof ArrayBuffer) return item; | ||
// Array | ||
if (_type2['default'].array(item)) { | ||
if (_type2.default.array(item)) { | ||
if (deep) { | ||
var a = []; | ||
var a = new Array(item.length); | ||
var i = undefined, | ||
l = undefined; | ||
for (i = 0, l = item.length; i < l; i++) a.push(cloner(true, item[i])); | ||
return a; | ||
for (var i = 0, l = item.length; i < l; i++) { | ||
a[i] = cloner(true, item[i]); | ||
}return a; | ||
} | ||
@@ -252,23 +251,24 @@ | ||
// Object | ||
if (_type2['default'].object(item)) { | ||
if (_type2.default.object(item)) { | ||
var o = {}; | ||
var i = undefined, | ||
l = undefined, | ||
k = undefined; | ||
// NOTE: could be possible to erase computed properties through `null`. | ||
var props = Object.getOwnPropertyNames(item); | ||
for (i = 0, l = props.length; i < l; i++) { | ||
k = props[i]; | ||
if (_type2['default'].lazyGetter(item, k)) { | ||
Object.defineProperty(o, k, { | ||
get: Object.getOwnPropertyDescriptor(item, k).get, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
} else { | ||
Object.defineProperty(o, k, { | ||
value: deep ? cloner(true, item[k]) : item[k], | ||
enumerable: Object.getOwnPropertyDescriptor(item, k).enumerable, | ||
for (var _i = 0, _l = props.length; _i < _l; _i++) { | ||
var name = props[_i]; | ||
var k = Object.getOwnPropertyDescriptor(item, name); | ||
if (k.enumerable === true) { | ||
if (k.get && k.get.isLazyGetter) { | ||
Object.defineProperty(o, name, { | ||
get: k.get, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
} else { | ||
o[name] = deep ? cloner(true, item[name]) : item[name]; | ||
} | ||
} else if (k.enumerable === false) { | ||
Object.defineProperty(o, name, { | ||
value: deep ? cloner(true, k.value) : k.value, | ||
enumerable: false, | ||
writable: true, | ||
@@ -316,3 +316,3 @@ configurable: true | ||
var ok = true, | ||
k = undefined; | ||
k = void 0; | ||
@@ -324,6 +324,6 @@ // If we reached here via a recursive call, object may be undefined because | ||
for (k in description) { | ||
if (_type2['default'].object(description[k])) { | ||
if (_type2.default.object(description[k])) { | ||
ok = ok && compare(object[k], description[k]); | ||
} else if (_type2['default'].array(description[k])) { | ||
ok = ok && !! ~description[k].indexOf(object[k]); | ||
} else if (_type2.default.array(description[k])) { | ||
ok = ok && !!~description[k].indexOf(object[k]); | ||
} else { | ||
@@ -345,3 +345,3 @@ if (object[k] !== description[k]) return false; | ||
function freezer(deep, o) { | ||
if (typeof o !== 'object' || o === null || o instanceof _monkey.Monkey) return; | ||
if ((typeof o === 'undefined' ? 'undefined' : _typeof(o)) !== 'object' || o === null || o instanceof _monkey.Monkey) return; | ||
@@ -355,18 +355,20 @@ Object.freeze(o); | ||
// Iterating through the elements | ||
var i = undefined, | ||
l = undefined; | ||
var i = void 0, | ||
l = void 0; | ||
for (i = 0, l = o.length; i < l; i++) freezer(true, o[i]); | ||
for (i = 0, l = o.length; i < l; i++) { | ||
deepFreeze(o[i]); | ||
} | ||
} else { | ||
var p = undefined, | ||
k = undefined; | ||
var p = void 0, | ||
k = void 0; | ||
for (k in o) { | ||
if (_type2['default'].lazyGetter(o, k)) continue; | ||
if (_type2.default.lazyGetter(o, k)) continue; | ||
p = o[k]; | ||
if (!p || !hasOwnProp.call(o, k) || typeof p !== 'object' || Object.isFrozen(p)) continue; | ||
if (!p || !hasOwnProp.call(o, k) || (typeof p === 'undefined' ? 'undefined' : _typeof(p)) !== 'object' || Object.isFrozen(p)) continue; | ||
freezer(true, p); | ||
deepFreeze(p); | ||
} | ||
@@ -376,12 +378,5 @@ } | ||
/** | ||
* Exporting both `freeze` and `deepFreeze` functions. | ||
* Note that if the engine does not support `Object.freeze` then this will | ||
* export noop functions instead. | ||
*/ | ||
var isFreezeSupported = typeof Object.freeze === 'function'; | ||
var freeze = freezer.bind(null, false), | ||
deepFreeze = freezer.bind(null, true); | ||
var freeze = isFreezeSupported ? freezer.bind(null, false) : noop, | ||
deepFreeze = isFreezeSupported ? freezer.bind(null, true) : noop; | ||
exports.freeze = freeze; | ||
@@ -404,2 +399,3 @@ exports.deepFreeze = deepFreeze; | ||
*/ | ||
var NOT_FOUND_OBJECT = { data: undefined, solvedPath: null, exists: false }; | ||
@@ -414,5 +410,5 @@ | ||
c = object, | ||
idx = undefined, | ||
i = undefined, | ||
l = undefined; | ||
idx = void 0, | ||
i = void 0, | ||
l = void 0; | ||
@@ -427,11 +423,11 @@ for (i = 0, l = path.length; i < l; i++) { | ||
if (typeof path[i] === 'function') { | ||
if (!_type2['default'].array(c)) return NOT_FOUND_OBJECT; | ||
if (!_type2.default.array(c)) return NOT_FOUND_OBJECT; | ||
idx = index(c, path[i]); | ||
if (! ~idx) return NOT_FOUND_OBJECT; | ||
if (!~idx) return NOT_FOUND_OBJECT; | ||
solvedPath.push(idx); | ||
c = c[idx]; | ||
} else if (typeof path[i] === 'object') { | ||
if (!_type2['default'].array(c)) return NOT_FOUND_OBJECT; | ||
} else if (_typeof(path[i]) === 'object') { | ||
if (!_type2.default.array(c)) return NOT_FOUND_OBJECT; | ||
@@ -441,3 +437,3 @@ idx = index(c, function (e) { | ||
}); | ||
if (! ~idx) return NOT_FOUND_OBJECT; | ||
if (!~idx) return NOT_FOUND_OBJECT; | ||
@@ -448,3 +444,3 @@ solvedPath.push(idx); | ||
solvedPath.push(path[i]); | ||
exists = typeof c === 'object' && path[i] in c; | ||
exists = (typeof c === 'undefined' ? 'undefined' : _typeof(c)) === 'object' && path[i] in c; | ||
c = c[path[i]]; | ||
@@ -464,3 +460,2 @@ } | ||
*/ | ||
function makeError(message, data) { | ||
@@ -491,6 +486,6 @@ var err = new Error(message); | ||
var t = undefined, | ||
i = undefined, | ||
l = undefined, | ||
k = undefined; | ||
var t = void 0, | ||
i = void 0, | ||
l = void 0, | ||
k = void 0; | ||
@@ -501,3 +496,3 @@ for (i = 1, l = objects.length; i < l; i++) { | ||
for (k in t) { | ||
if (deep && _type2['default'].object(t[k]) && !(t[k] instanceof _monkey.Monkey)) { | ||
if (deep && _type2.default.object(t[k]) && !(t[k] instanceof _monkey.Monkey)) { | ||
o[k] = merger(true, o[k] || {}, t[k]); | ||
@@ -523,2 +518,18 @@ } else { | ||
/** | ||
* Function returning a string hash from a non-dynamic path expressed as an | ||
* array. | ||
* | ||
* @param {array} path - The path to hash. | ||
* @return {string} string - The resultant hash. | ||
*/ | ||
function hashPath(path) { | ||
return 'λ' + path.map(function (step) { | ||
if (_type2.default.function(step) || _type2.default.object(step)) return '#' + uniqid() + '#'; | ||
return step; | ||
}).join('λ'); | ||
} | ||
/** | ||
* Solving a potentially relative path. | ||
@@ -530,3 +541,2 @@ * | ||
*/ | ||
function solveRelativePath(base, to) { | ||
@@ -571,13 +581,12 @@ var solvedPath = []; | ||
*/ | ||
function solveUpdate(affectedPaths, comparedPaths) { | ||
var i = undefined, | ||
j = undefined, | ||
k = undefined, | ||
l = undefined, | ||
m = undefined, | ||
n = undefined, | ||
p = undefined, | ||
c = undefined, | ||
s = undefined; | ||
var i = void 0, | ||
j = void 0, | ||
k = void 0, | ||
l = void 0, | ||
m = void 0, | ||
n = void 0, | ||
p = void 0, | ||
c = void 0, | ||
s = void 0; | ||
@@ -622,3 +631,2 @@ // Looping through possible paths | ||
*/ | ||
function splice(array, startIndex, nb) { | ||
@@ -633,4 +641,4 @@ for (var _len2 = arguments.length, elements = Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) { | ||
// Solving startIndex | ||
if (_type2['default']['function'](startIndex)) startIndex = index(array, startIndex); | ||
if (_type2['default'].object(startIndex)) startIndex = index(array, function (e) { | ||
if (_type2.default.function(startIndex)) startIndex = index(array, startIndex); | ||
if (_type2.default.object(startIndex)) startIndex = index(array, function (e) { | ||
return compare(e, startIndex); | ||
@@ -651,3 +659,3 @@ }); | ||
*/ | ||
var uniqid = (function () { | ||
var uniqid = function () { | ||
var i = 0; | ||
@@ -658,4 +666,4 @@ | ||
}; | ||
})(); | ||
}(); | ||
exports.uniqid = uniqid; |
@@ -1,19 +0,10 @@ | ||
/** | ||
* Baobab Monkeys | ||
* =============== | ||
* | ||
* Exposing both handy monkey definitions and the underlying working class. | ||
*/ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.Monkey = exports.MonkeyDefinition = undefined; | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _type = require('./type'); | ||
@@ -29,2 +20,12 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** | ||
* Baobab Monkeys | ||
* =============== | ||
* | ||
* Exposing both handy monkey definitions and the underlying working class. | ||
*/ | ||
/** | ||
@@ -38,4 +39,3 @@ * Monkey Definition class | ||
*/ | ||
var MonkeyDefinition = function MonkeyDefinition(definition) { | ||
var MonkeyDefinition = exports.MonkeyDefinition = function MonkeyDefinition(definition) { | ||
var _this = this; | ||
@@ -45,3 +45,3 @@ | ||
var monkeyType = _type2['default'].monkeyDefinition(definition); | ||
var monkeyType = _type2.default.monkeyDefinition(definition); | ||
@@ -63,3 +63,3 @@ if (!monkeyType) throw (0, _helpers.makeError)('Baobab.monkey: invalid definition.', { definition: definition }); | ||
if (_type2['default'].object(definition[definition.length - 1])) { | ||
if (_type2.default.object(definition[definition.length - 1])) { | ||
offset++; | ||
@@ -81,4 +81,4 @@ options = definition[definition.length - 1]; | ||
// Does the definition contain dynamic paths | ||
this.hasDynamicPaths = this.paths.some(_type2['default'].dynamicPath); | ||
} | ||
this.hasDynamicPaths = this.paths.some(_type2.default.dynamicPath); | ||
}; | ||
@@ -92,7 +92,5 @@ /** | ||
*/ | ||
; | ||
exports.MonkeyDefinition = MonkeyDefinition; | ||
var Monkey = (function () { | ||
var Monkey = exports.Monkey = function () { | ||
function Monkey(tree, pathInTree, definition) { | ||
@@ -156,5 +154,5 @@ var _this2 = this; | ||
this.recursiveListener = function (_ref2) { | ||
var _ref2$data = _ref2.data; | ||
var monkey = _ref2$data.monkey; | ||
var path = _ref2$data.path; | ||
var _ref2$data = _ref2.data, | ||
monkey = _ref2$data.monkey, | ||
path = _ref2$data.path; | ||
@@ -187,2 +185,3 @@ if (_this2.state.killed) return; | ||
_createClass(Monkey, [{ | ||
@@ -193,5 +192,5 @@ key: 'relatedPaths', | ||
var recursive = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0]; | ||
var recursive = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; | ||
var paths = undefined; | ||
var paths = void 0; | ||
@@ -203,3 +202,3 @@ if (this.definition.hasDynamicPaths) paths = this.depPaths.map(function (p) { | ||
var isRecursive = recursive && this.depPaths.some(function (p) { | ||
return !!_type2['default'].monkeyPath(_this3.tree._monkeys, p); | ||
return !!_type2.default.monkeyPath(_this3.tree._monkeys, p); | ||
}); | ||
@@ -210,3 +209,3 @@ | ||
return paths.reduce(function (accumulatedPaths, path) { | ||
var monkeyPath = _type2['default'].monkeyPath(_this3.tree._monkeys, path); | ||
var monkeyPath = _type2.default.monkeyPath(_this3.tree._monkeys, path); | ||
@@ -228,8 +227,11 @@ if (!monkeyPath) return accumulatedPaths.concat([path]); | ||
*/ | ||
}, { | ||
key: 'update', | ||
value: function update() { | ||
var _this4 = this; | ||
var deps = this.tree.project(this.projection); | ||
var lazyGetter = (function (tree, def, data) { | ||
var lazyGetter = function (tree, def, data) { | ||
var cache = null, | ||
@@ -245,2 +247,6 @@ alreadyComputed = false; | ||
// update tree affected paths | ||
var hash = (0, _helpers.hashPath)(_this4.path); | ||
tree._affectedPathsIndex[hash] = true; | ||
alreadyComputed = true; | ||
@@ -251,3 +257,3 @@ } | ||
}; | ||
})(this.tree, this.definition, deps); | ||
}(this.tree, this.definition, deps); | ||
@@ -258,3 +264,3 @@ lazyGetter.isLazyGetter = true; | ||
if (this.tree.options.lazyMonkeys) { | ||
this.tree._data = (0, _update3['default'])(this.tree._data, this.path, { | ||
this.tree._data = (0, _update3.default)(this.tree._data, this.path, { | ||
type: 'monkey', | ||
@@ -264,3 +270,3 @@ value: lazyGetter | ||
} else { | ||
var result = (0, _update3['default'])(this.tree._data, this.path, { | ||
var result = (0, _update3.default)(this.tree._data, this.path, { | ||
type: 'set', | ||
@@ -285,2 +291,3 @@ value: lazyGetter(), | ||
*/ | ||
}, { | ||
@@ -305,4 +312,2 @@ key: 'release', | ||
return Monkey; | ||
})(); | ||
exports.Monkey = Monkey; | ||
}(); |
@@ -1,15 +0,17 @@ | ||
/** | ||
* Baobab Type Checking | ||
* ===================== | ||
* | ||
* Helpers functions used throughout the library to perform some type | ||
* tests at runtime. | ||
* | ||
*/ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /** | ||
* Baobab Type Checking | ||
* ===================== | ||
* | ||
* Helpers functions used throughout the library to perform some type | ||
* tests at runtime. | ||
* | ||
*/ | ||
var _monkey = require('./monkey'); | ||
@@ -61,3 +63,3 @@ | ||
type.object = function (target) { | ||
return target && typeof target === 'object' && !Array.isArray(target) && !(target instanceof Date) && !(target instanceof RegExp) && !(typeof Map === 'function' && target instanceof Map) && !(typeof Set === 'function' && target instanceof Set); | ||
return target && (typeof target === 'undefined' ? 'undefined' : _typeof(target)) === 'object' && !Array.isArray(target) && !(target instanceof Date) && !(target instanceof RegExp) && !(typeof Map === 'function' && target instanceof Map) && !(typeof Set === 'function' && target instanceof Set); | ||
}; | ||
@@ -91,3 +93,3 @@ | ||
*/ | ||
type['function'] = function (target) { | ||
type.function = function (target) { | ||
return typeof target === 'function'; | ||
@@ -152,3 +154,3 @@ }; | ||
return path.some(function (step) { | ||
return type['function'](step) || type.object(step); | ||
return type.function(step) || type.object(step); | ||
}); | ||
@@ -169,4 +171,4 @@ }; | ||
var c = data, | ||
i = undefined, | ||
l = undefined; | ||
i = void 0, | ||
l = void 0; | ||
@@ -176,3 +178,3 @@ for (i = 0, l = path.length; i < l; i++) { | ||
if (typeof c !== 'object') return null; | ||
if ((typeof c === 'undefined' ? 'undefined' : _typeof(c)) !== 'object') return null; | ||
@@ -209,3 +211,3 @@ c = c[path[i]]; | ||
if (type.object(definition)) { | ||
if (!type['function'](definition.get) || definition.cursors && (!type.object(definition.cursors) || !Object.keys(definition.cursors).every(function (k) { | ||
if (!type.function(definition.get) || definition.cursors && (!type.object(definition.cursors) || !Object.keys(definition.cursors).every(function (k) { | ||
return type.path(definition.cursors[k]); | ||
@@ -220,3 +222,3 @@ }))) return null; | ||
if (!type['function'](definition[definition.length - offset]) || !definition.slice(0, -offset).every(function (p) { | ||
if (!type.function(definition[definition.length - offset]) || !definition.slice(0, -offset).every(function (p) { | ||
return type.path(p); | ||
@@ -254,6 +256,5 @@ })) return null; | ||
type.operationType = function (string) { | ||
return typeof string === 'string' && !! ~VALID_OPERATIONS.indexOf(string); | ||
return typeof string === 'string' && !!~VALID_OPERATIONS.indexOf(string); | ||
}; | ||
exports['default'] = type; | ||
module.exports = exports['default']; | ||
exports.default = type; |
@@ -1,18 +0,8 @@ | ||
/** | ||
* Baobab Update | ||
* ============== | ||
* | ||
* The tree's update scheme. | ||
*/ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports['default'] = update; | ||
exports.default = update; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } } | ||
var _type = require('./type'); | ||
@@ -24,2 +14,12 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } /** | ||
* Baobab Update | ||
* ============== | ||
* | ||
* The tree's update scheme. | ||
*/ | ||
function err(operation, expectedTarget, path) { | ||
@@ -39,11 +39,11 @@ return (0, _helpers.makeError)('Baobab.update: cannot apply the "' + operation + '" on ' + ('a non ' + expectedTarget + ' (path: /' + path.join('/') + ').'), { path: path }); | ||
*/ | ||
function update(data, path, operation) { | ||
var opts = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
var operationType = operation.type; | ||
var value = operation.value; | ||
var _operation$options = operation.options; | ||
var operationOptions = _operation$options === undefined ? {} : _operation$options; | ||
var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
var operationType = operation.type, | ||
value = operation.value, | ||
_operation$options = operation.options, | ||
operationOptions = _operation$options === undefined ? {} : _operation$options; | ||
// Dummy root, so we can shift and alter the root | ||
var dummy = { root: data }, | ||
@@ -55,5 +55,5 @@ dummyPath = ['root'].concat(_toConsumableArray(path)), | ||
var p = dummy, | ||
i = undefined, | ||
l = undefined, | ||
s = undefined; | ||
i = void 0, | ||
l = void 0, | ||
s = void 0; | ||
@@ -81,3 +81,3 @@ for (i = 0, l = dummyPath.length; i < l; i++) { | ||
if (_type2['default'].lazyGetter(p, s)) { | ||
if (_type2.default.lazyGetter(p, s)) { | ||
Object.defineProperty(p, s, { | ||
@@ -115,3 +115,3 @@ value: value, | ||
if (_type2['default'].lazyGetter(p, s)) { | ||
if (_type2.default.lazyGetter(p, s)) { | ||
Object.defineProperty(p, s, { | ||
@@ -133,3 +133,3 @@ value: result, | ||
else if (operationType === 'push') { | ||
if (!_type2['default'].array(p[s])) throw err('push', 'array', currentPath); | ||
if (!_type2.default.array(p[s])) throw err('push', 'array', currentPath); | ||
@@ -143,3 +143,3 @@ if (opts.persistent) p[s] = p[s].concat([value]);else p[s].push(value); | ||
else if (operationType === 'unshift') { | ||
if (!_type2['default'].array(p[s])) throw err('unshift', 'array', currentPath); | ||
if (!_type2.default.array(p[s])) throw err('unshift', 'array', currentPath); | ||
@@ -153,3 +153,3 @@ if (opts.persistent) p[s] = [value].concat(p[s]);else p[s].unshift(value); | ||
else if (operationType === 'concat') { | ||
if (!_type2['default'].array(p[s])) throw err('concat', 'array', currentPath); | ||
if (!_type2.default.array(p[s])) throw err('concat', 'array', currentPath); | ||
@@ -163,3 +163,3 @@ if (opts.persistent) p[s] = p[s].concat(value);else p[s].push.apply(p[s], value); | ||
else if (operationType === 'splice') { | ||
if (!_type2['default'].array(p[s])) throw err('splice', 'array', currentPath); | ||
if (!_type2.default.array(p[s])) throw err('splice', 'array', currentPath); | ||
@@ -173,3 +173,3 @@ if (opts.persistent) p[s] = _helpers.splice.apply(null, [p[s]].concat(value));else p[s].splice.apply(p[s], value); | ||
else if (operationType === 'pop') { | ||
if (!_type2['default'].array(p[s])) throw err('pop', 'array', currentPath); | ||
if (!_type2.default.array(p[s])) throw err('pop', 'array', currentPath); | ||
@@ -183,3 +183,3 @@ if (opts.persistent) p[s] = (0, _helpers.splice)(p[s], -1, 1);else p[s].pop(); | ||
else if (operationType === 'shift') { | ||
if (!_type2['default'].array(p[s])) throw err('shift', 'array', currentPath); | ||
if (!_type2.default.array(p[s])) throw err('shift', 'array', currentPath); | ||
@@ -193,3 +193,3 @@ if (opts.persistent) p[s] = (0, _helpers.splice)(p[s], 0, 1);else p[s].shift(); | ||
else if (operationType === 'unset') { | ||
if (_type2['default'].object(p)) delete p[s];else if (_type2['default'].array(p)) p.splice(s, 1); | ||
if (_type2.default.object(p)) delete p[s];else if (_type2.default.array(p)) p.splice(s, 1); | ||
} | ||
@@ -201,3 +201,3 @@ | ||
else if (operationType === 'merge') { | ||
if (!_type2['default'].object(p[s])) throw err('merge', 'object', currentPath); | ||
if (!_type2.default.object(p[s])) throw err('merge', 'object', currentPath); | ||
@@ -211,3 +211,3 @@ if (opts.persistent) p[s] = (0, _helpers.shallowMerge)({}, p[s], value);else p[s] = (0, _helpers.shallowMerge)(p[s], value); | ||
else if (operationType === 'deepMerge') { | ||
if (!_type2['default'].object(p[s])) throw err('deepMerge', 'object', currentPath); | ||
if (!_type2.default.object(p[s])) throw err('deepMerge', 'object', currentPath); | ||
@@ -224,3 +224,3 @@ if (opts.persistent) p[s] = (0, _helpers.deepMerge)({}, p[s], value);else p[s] = (0, _helpers.deepMerge)(p[s], value); | ||
// If we reached a leaf, we override by setting an empty object | ||
else if (_type2['default'].primitive(p[s])) { | ||
else if (_type2.default.primitive(p[s])) { | ||
p[s] = {}; | ||
@@ -241,8 +241,6 @@ } | ||
// If we are updating a dynamic node, we need not return the affected node | ||
if (_type2['default'].lazyGetter(p, s)) return { data: dummy.root }; | ||
if (_type2.default.lazyGetter(p, s)) return { data: dummy.root }; | ||
// Returning new data object | ||
return { data: dummy.root, node: p[s] }; | ||
} | ||
module.exports = exports['default']; | ||
} |
@@ -1,24 +0,9 @@ | ||
/** | ||
* Baobab Watchers | ||
* ================ | ||
* | ||
* Abstraction used to listen and retrieve data from multiple parts of a | ||
* Baobab tree at once. | ||
*/ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _emmett = require('emmett'); | ||
@@ -38,2 +23,17 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** | ||
* Baobab Watchers | ||
* ================ | ||
* | ||
* Abstraction used to listen and retrieve data from multiple parts of a | ||
* Baobab tree at once. | ||
*/ | ||
/** | ||
@@ -46,18 +46,15 @@ * Watcher class. | ||
*/ | ||
var Watcher = (function (_Emitter) { | ||
var Watcher = function (_Emitter) { | ||
_inherits(Watcher, _Emitter); | ||
function Watcher(tree, mapping) { | ||
var _this = this; | ||
_classCallCheck(this, Watcher); | ||
_get(Object.getPrototypeOf(Watcher.prototype), 'constructor', this).call(this); | ||
// Properties | ||
this.tree = tree; | ||
this.mapping = null; | ||
var _this = _possibleConstructorReturn(this, (Watcher.__proto__ || Object.getPrototypeOf(Watcher)).call(this)); | ||
this.state = { | ||
_this.tree = tree; | ||
_this.mapping = null; | ||
_this.state = { | ||
killed: false | ||
@@ -67,6 +64,6 @@ }; | ||
// Initializing | ||
this.refresh(mapping); | ||
_this.refresh(mapping); | ||
// Listening | ||
this.handler = function (e) { | ||
_this.handler = function (e) { | ||
if (_this.state.killed) return; | ||
@@ -79,3 +76,4 @@ | ||
this.tree.on('update', this.handler); | ||
_this.tree.on('update', _this.handler); | ||
return _this; | ||
} | ||
@@ -89,2 +87,3 @@ | ||
_createClass(Watcher, [{ | ||
@@ -99,3 +98,3 @@ key: 'getWatchedPaths', | ||
// Watcher mappings can accept a cursor | ||
if (v instanceof _cursor2['default']) return v.solvedPath; | ||
if (v instanceof _cursor2.default) return v.solvedPath; | ||
@@ -111,3 +110,3 @@ return _this2.mapping[k]; | ||
// Dynamic path? | ||
if (_type2['default'].dynamicPath(p)) p = (0, _helpers.getIn)(_this2.tree._data, p).solvedPath; | ||
if (_type2.default.dynamicPath(p)) p = (0, _helpers.getIn)(_this2.tree._data, p).solvedPath; | ||
@@ -117,3 +116,3 @@ if (!p) return cp; | ||
// Facet path? | ||
var monkeyPath = _type2['default'].monkeyPath(_this2.tree._monkeys, p); | ||
var monkeyPath = _type2.default.monkeyPath(_this2.tree._monkeys, p); | ||
@@ -131,2 +130,3 @@ if (monkeyPath) return cp.concat((0, _helpers.getIn)(_this2.tree._monkeys, monkeyPath).data.relatedPaths()); | ||
*/ | ||
}, { | ||
@@ -142,3 +142,3 @@ key: 'getCursors', | ||
if (path instanceof _cursor2['default']) cursors[k] = path;else cursors[k] = _this3.tree.select(path); | ||
if (path instanceof _cursor2.default) cursors[k] = path;else cursors[k] = _this3.tree.select(path); | ||
}); | ||
@@ -155,2 +155,3 @@ | ||
*/ | ||
}, { | ||
@@ -160,3 +161,3 @@ key: 'refresh', | ||
if (!_type2['default'].watcherMapping(mapping)) throw (0, _helpers.makeError)('Baobab.watch: invalid mapping.', { mapping: mapping }); | ||
if (!_type2.default.watcherMapping(mapping)) throw (0, _helpers.makeError)('Baobab.watch: invalid mapping.', { mapping: mapping }); | ||
@@ -169,3 +170,3 @@ this.mapping = mapping; | ||
for (var k in mapping) { | ||
projection[k] = mapping[k] instanceof _cursor2['default'] ? mapping[k].path : mapping[k]; | ||
projection[k] = mapping[k] instanceof _cursor2.default ? mapping[k].path : mapping[k]; | ||
}this.get = this.tree.project.bind(this.tree, projection); | ||
@@ -177,2 +178,3 @@ } | ||
*/ | ||
}, { | ||
@@ -189,5 +191,4 @@ key: 'release', | ||
return Watcher; | ||
})(_emmett2['default']); | ||
}(_emmett2.default); | ||
exports['default'] = Watcher; | ||
module.exports = exports['default']; | ||
exports.default = Watcher; |
{ | ||
"name": "baobab", | ||
"version": "2.5.0", | ||
"version": "2.5.1", | ||
"description": "JavaScript persistent data tree with cursors.", | ||
@@ -10,18 +10,20 @@ "main": "./dist/baobab.js", | ||
"devDependencies": { | ||
"@yomguithereal/eslint-config": "^1.1.1", | ||
"@yomguithereal/eslint-config": "^4.0.0", | ||
"add-banner": "^0.1.0", | ||
"async": "^1.2.1", | ||
"babel": "^5.6.14", | ||
"babelify": "^6.1.2", | ||
"benchmark": "^1.0.0", | ||
"browserify": "^12.0.1", | ||
"eslint": "^1.1.0", | ||
"lodash": "^3.6.0", | ||
"async": "^2.5.0", | ||
"babel-cli": "^6.26.0", | ||
"babel-core": "^6.26.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babelify": "^8.0.0", | ||
"benchmark": "^2.1.4", | ||
"browserify": "^14.5.0", | ||
"eslint": "^4.10.0", | ||
"lodash": "^4.17.4", | ||
"mkdirp": "^0.5.1", | ||
"mocha": "^2.0.1", | ||
"uglify-js": "^2.6.1" | ||
"mocha": "^4.0.1", | ||
"uglify-js": "^3.1.6" | ||
}, | ||
"scripts": { | ||
"benchmark": "babel-node benchmark.js", | ||
"build": "mkdirp build && browserify ./src/baobab.js -t [babelify --loose all] -s Baobab -o ./build/baobab.js && uglifyjs ./build/baobab.js -c -m -o ./build/baobab.min.js && node ./scripts/banner.js", | ||
"build": "mkdirp build && browserify ./src/baobab.js -s Baobab -o ./build/baobab.js && uglifyjs ./build/baobab.js -c -m -o ./build/baobab.min.js && node ./scripts/banner.js", | ||
"check": "npm test && npm run lint && npm run build", | ||
@@ -31,3 +33,3 @@ "dist": "babel ./src --out-dir dist", | ||
"prepublish": "npm run dist", | ||
"test": "mocha -R spec --compilers js:babel/register ./test/endpoint.js" | ||
"test": "mocha -R spec --require babel-core/register ./test/endpoint.js" | ||
}, | ||
@@ -52,3 +54,25 @@ "repository": { | ||
}, | ||
"homepage": "https://github.com/Yomguithereal/baobab" | ||
"homepage": "https://github.com/Yomguithereal/baobab", | ||
"browserify": { | ||
"transform": [ | ||
[ | ||
"babelify", | ||
{ | ||
"presets": [ | ||
[ | ||
"es2015", | ||
{ | ||
"loose": true | ||
} | ||
] | ||
] | ||
} | ||
] | ||
] | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"es2015" | ||
] | ||
} | ||
} |
@@ -562,3 +562,3 @@ [![Build Status](https://travis-ci.org/Yomguithereal/baobab.svg)](https://travis-ci.org/Yomguithereal/baobab) | ||
As such, while monkeys represent reduction of the current state (a filtered list used by multiple component throughout your app, for instance), they do have a physical existence within the tree. | ||
As such, while monkeys represent reduction of the current state (a filtered list used by multiple components throughout your app, for instance), they do have a physical existence within the tree. | ||
@@ -565,0 +565,0 @@ This means that you can add / modify / move / remove monkeys from the tree at runtime and place them wherever you want. |
@@ -25,3 +25,3 @@ /** | ||
shallowMerge, | ||
uniqid | ||
hashPath | ||
} = helpers; | ||
@@ -62,18 +62,3 @@ | ||
/** | ||
* Function returning a string hash from a non-dynamic path expressed as an | ||
* array. | ||
* | ||
* @param {array} path - The path to hash. | ||
* @return {string} string - The resultant hash. | ||
*/ | ||
function hashPath(path) { | ||
return 'λ' + path.map(step => { | ||
if (type.function(step) || type.object(step)) | ||
return `#${uniqid()}#`; | ||
return step; | ||
}).join('λ'); | ||
} | ||
/** | ||
@@ -80,0 +65,0 @@ * Baobab class |
/* eslint eqeqeq: 0 */ | ||
/* eslint no-use-before-define: 0 */ | ||
/** | ||
@@ -12,7 +12,2 @@ * Baobab Helpers | ||
/** | ||
* Noop function | ||
*/ | ||
const noop = Function.prototype; | ||
const hasOwnProp = {}.hasOwnProperty; | ||
@@ -185,9 +180,6 @@ | ||
if (deep) { | ||
const a = []; | ||
const a = new Array(item.length); | ||
let i, | ||
l; | ||
for (i = 0, l = item.length; i < l; i++) | ||
a.push(cloner(true, item[i])); | ||
for (let i = 0, l = item.length; i < l; i++) | ||
a[i] = cloner(true, item[i]); | ||
return a; | ||
@@ -211,19 +203,23 @@ } | ||
let i, l, k; | ||
// NOTE: could be possible to erase computed properties through `null`. | ||
const props = Object.getOwnPropertyNames(item); | ||
for (i = 0, l = props.length; i < l; i++) { | ||
k = props[i]; | ||
if (type.lazyGetter(item, k)) { | ||
Object.defineProperty(o, k, { | ||
get: Object.getOwnPropertyDescriptor(item, k).get, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
for (let i = 0, l = props.length; i < l; i++) { | ||
const name = props[i]; | ||
const k = Object.getOwnPropertyDescriptor(item, name); | ||
if (k.enumerable === true) { | ||
if (k.get && k.get.isLazyGetter) { | ||
Object.defineProperty(o, name, { | ||
get: k.get, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
} | ||
else { | ||
o[name] = deep ? cloner(true, item[name]) : item[name]; | ||
} | ||
} | ||
else { | ||
Object.defineProperty(o, k, { | ||
value: deep ? cloner(true, item[k]) : item[k], | ||
enumerable: Object.getOwnPropertyDescriptor(item, k).enumerable, | ||
else if (k.enumerable === false) { | ||
Object.defineProperty(o, name, { | ||
value: deep ? cloner(true, k.value) : k.value, | ||
enumerable: false, | ||
writable: true, | ||
@@ -318,3 +314,3 @@ configurable: true | ||
for (i = 0, l = o.length; i < l; i++) | ||
freezer(true, o[i]); | ||
deepFreeze(o[i]); | ||
} | ||
@@ -337,3 +333,3 @@ else { | ||
freezer(true, p); | ||
deepFreeze(p); | ||
} | ||
@@ -343,12 +339,5 @@ } | ||
/** | ||
* Exporting both `freeze` and `deepFreeze` functions. | ||
* Note that if the engine does not support `Object.freeze` then this will | ||
* export noop functions instead. | ||
*/ | ||
const isFreezeSupported = (typeof Object.freeze === 'function'); | ||
const freeze = freezer.bind(null, false), | ||
deepFreeze = freezer.bind(null, true); | ||
const freeze = isFreezeSupported ? freezer.bind(null, false) : noop, | ||
deepFreeze = isFreezeSupported ? freezer.bind(null, true) : noop; | ||
export {freeze, deepFreeze}; | ||
@@ -485,2 +474,18 @@ | ||
/** | ||
* Function returning a string hash from a non-dynamic path expressed as an | ||
* array. | ||
* | ||
* @param {array} path - The path to hash. | ||
* @return {string} string - The resultant hash. | ||
*/ | ||
export function hashPath(path) { | ||
return 'λ' + path.map(step => { | ||
if (type.function(step) || type.object(step)) | ||
return `#${uniqid()}#`; | ||
return step; | ||
}).join('λ'); | ||
} | ||
/** | ||
* Solving a potentially relative path. | ||
@@ -487,0 +492,0 @@ * |
@@ -14,3 +14,4 @@ /** | ||
solveUpdate, | ||
solveRelativePath | ||
solveRelativePath, | ||
hashPath | ||
} from './helpers'; | ||
@@ -198,7 +199,7 @@ | ||
const lazyGetter = (function(tree, def, data) { | ||
const lazyGetter = ((tree, def, data) => { | ||
let cache = null, | ||
alreadyComputed = false; | ||
return function() { | ||
return () => { | ||
@@ -216,2 +217,6 @@ if (!alreadyComputed) { | ||
// update tree affected paths | ||
const hash = hashPath(this.path); | ||
tree._affectedPathsIndex[hash] = true; | ||
alreadyComputed = true; | ||
@@ -218,0 +223,0 @@ } |
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
217776
14
5006