ancient-cursor
Advanced tools
Comparing version 0.2.0 to 0.2.1
"use strict"; | ||
exports.__esModule = true; | ||
var _ = require("lodash"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const _ = require("lodash"); | ||
function toPath(data, paths) { | ||
@@ -9,6 +9,6 @@ if (typeof (paths) === 'string') | ||
throw new Error('Path must be array TBundlePaths.'); | ||
var pointer = data; | ||
var result = ''; | ||
_.each(paths, function (p) { | ||
var path; | ||
let pointer = data; | ||
let result = ''; | ||
_.each(paths, (p) => { | ||
let path; | ||
if (_.isString(p)) { | ||
@@ -20,3 +20,3 @@ path = p; | ||
if (path === '-1') | ||
throw new Error("Not founded by selector in path " + paths + "."); | ||
throw new Error(`Not founded by selector in path ${paths}.`); | ||
} | ||
@@ -38,10 +38,10 @@ pointer = getByPath(pointer, path); | ||
function prepare(container, bundle) { | ||
var bundlePath = _.toPath(toPath(container.data, bundle.path)); | ||
var oldValue = _.clone(get(container.data, bundlePath)); | ||
return { oldValue: oldValue, bundlePath: bundlePath }; | ||
const bundlePath = _.toPath(toPath(container.data, bundle.path)); | ||
const oldValue = _.clone(get(container.data, bundlePath)); | ||
return { oldValue, bundlePath }; | ||
} | ||
exports.prepare = prepare; | ||
var bundleParsers = { | ||
set: function (container, bundle) { | ||
var _a = prepare(container, bundle), oldValue = _a.oldValue, bundlePath = _a.bundlePath; | ||
const bundleParsers = { | ||
set(container, bundle) { | ||
const { oldValue, bundlePath } = prepare(container, bundle); | ||
if (!bundlePath.length) { | ||
@@ -53,7 +53,7 @@ container.data = bundle.value; | ||
} | ||
var newValue = get(container.data, bundlePath); | ||
return { oldValue: oldValue, newValue: newValue, bundlePath: bundlePath, bundle: bundle, data: container.data }; | ||
const newValue = get(container.data, bundlePath); | ||
return { oldValue, newValue, bundlePath, bundle, data: container.data }; | ||
}, | ||
extend: function (container, bundle) { | ||
var _a = prepare(container, bundle), oldValue = _a.oldValue, bundlePath = _a.bundlePath; | ||
extend(container, bundle) { | ||
const { oldValue, bundlePath } = prepare(container, bundle); | ||
if (!bundlePath.length) { | ||
@@ -65,7 +65,7 @@ _.extend(container.data, bundle.value); | ||
} | ||
var newValue = get(container.data, bundlePath); | ||
return { oldValue: oldValue, newValue: newValue, bundlePath: bundlePath, bundle: bundle, data: container.data }; | ||
const newValue = get(container.data, bundlePath); | ||
return { oldValue, newValue, bundlePath, bundle, data: container.data }; | ||
}, | ||
unset: function (container, bundle) { | ||
var _a = prepare(container, bundle), oldValue = _a.oldValue, bundlePath = _a.bundlePath; | ||
unset(container, bundle) { | ||
const { oldValue, bundlePath } = prepare(container, bundle); | ||
if (!bundlePath.length) { | ||
@@ -75,30 +75,50 @@ container.data = undefined; | ||
else { | ||
var parent_1 = get(container.data, bundlePath.slice(0, bundlePath.length - 1)); | ||
delete parent_1[bundlePath[bundlePath.length - 1]]; | ||
const parent = get(container.data, bundlePath.slice(0, bundlePath.length - 1)); | ||
delete parent[bundlePath[bundlePath.length - 1]]; | ||
} | ||
var newValue = get(container.data, bundlePath); | ||
return { oldValue: oldValue, newValue: newValue, bundlePath: bundlePath, bundle: bundle, data: container.data }; | ||
const newValue = get(container.data, bundlePath); | ||
return { oldValue, newValue, bundlePath, bundle, data: container.data }; | ||
}, | ||
splice: function (container, bundle) { | ||
var _a = prepare(container, bundle), oldValue = _a.oldValue, bundlePath = _a.bundlePath; | ||
var value = get(container.data, bundlePath); | ||
splice(container, bundle) { | ||
const { oldValue, bundlePath } = prepare(container, bundle); | ||
const value = get(container.data, bundlePath); | ||
if (!_.isArray(value)) { | ||
throw new Error("Data by path \"" + bundle.path + "\" is not an array but " + typeof (value) + "."); | ||
throw new Error(`Data by path "${bundle.path}" is not an array but ${typeof (value)}.`); | ||
} | ||
value.splice.apply(value, [bundle.start, bundle.deleteCount].concat(bundle.values)); | ||
var newValue = value; | ||
return { oldValue: oldValue, newValue: newValue, bundlePath: bundlePath, bundle: bundle, data: container.data }; | ||
value.splice(bundle.start, bundle.deleteCount, ...bundle.values); | ||
const newValue = value; | ||
return { oldValue, newValue, bundlePath, bundle, data: container.data }; | ||
}, | ||
remove: function (container, bundle) { | ||
var _a = prepare(container, bundle), oldValue = _a.oldValue, bundlePath = _a.bundlePath; | ||
var value = get(container.data, bundlePath); | ||
remove(container, bundle) { | ||
const { oldValue, bundlePath } = prepare(container, bundle); | ||
const value = get(container.data, bundlePath); | ||
if (!_.isArray(value)) { | ||
throw new Error("Data by path \"" + bundle.path + "\" is not an array but " + typeof (value) + "."); | ||
throw new Error(`Data by path "${bundle.path}" is not an array but ${typeof (value)}.`); | ||
} | ||
_.remove(value, _.matches(bundle.selector)); | ||
var newValue = value; | ||
return { oldValue: oldValue, newValue: newValue, bundlePath: bundlePath, bundle: bundle, data: container.data }; | ||
} | ||
const newValue = value; | ||
return { oldValue, newValue, bundlePath, bundle, data: container.data }; | ||
}, | ||
push(container, bundle) { | ||
const { oldValue, bundlePath } = prepare(container, bundle); | ||
const value = get(container.data, bundlePath); | ||
if (!_.isArray(value)) { | ||
throw new Error(`Data by path "${bundle.path}" is not an array but ${typeof (value)}.`); | ||
} | ||
value.push(...bundle.value); | ||
const newValue = value; | ||
return { oldValue, newValue, bundlePath, bundle, data: container.data }; | ||
}, | ||
move(container, bundle) { | ||
const { oldValue, bundlePath } = prepare(container, bundle); | ||
const value = get(container.data, bundlePath); | ||
if (!_.isArray(value)) { | ||
throw new Error(`Data by path "${bundle.path}" is not an array but ${typeof (value)}.`); | ||
} | ||
value.splice(bundle.to, 0, value.splice(bundle.from, 1)[0]); | ||
const newValue = value; | ||
return { oldValue, newValue, bundlePath, bundle, data: container.data }; | ||
}, | ||
}; | ||
exports.bundleParsers = bundleParsers; | ||
//# sourceMappingURL=bundle.js.map |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
exports.__esModule = true; | ||
var _ = require("lodash"); | ||
var bundle_1 = require("./bundle"); | ||
var cursors_manager_1 = require("./cursors-manager"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const _ = require("lodash"); | ||
const bundle_1 = require("./bundle"); | ||
const cursors_manager_1 = require("./cursors-manager"); | ||
function mixin(superClass) { | ||
return (function (_super) { | ||
__extends(ChildsCursorsManager, _super); | ||
function ChildsCursorsManager() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
ChildsCursorsManager.prototype.maintain = function (path) { | ||
var _this = this; | ||
return function (_a) { | ||
var watch = _a.watch, bundlePath = _a.bundlePath; | ||
watch(path, function (_a) { | ||
var isClone = _a.isClone, oldValue = _a.oldValue, newValue = _a.newValue, bundlePath = _a.bundlePath, watchPath = _a.watchPath, localBundlePath = _a.localBundlePath, localWatchPath = _a.localWatchPath; | ||
return class ChildsCursorsManager extends superClass { | ||
maintain(path) { | ||
return ({ watch, bundlePath }) => { | ||
watch(path, ({ isClone, oldValue, newValue, bundlePath, watchPath, localBundlePath, localWatchPath, }) => { | ||
if (localBundlePath.length) { | ||
var id = localBundlePath[0]; | ||
var childData = bundle_1.get(newValue, id); | ||
const id = localBundlePath[0]; | ||
const childData = bundle_1.get(newValue, id); | ||
if (childData) { | ||
if (!_this.nodes[id]) | ||
_this.create(id); | ||
_this.nodes[id].exec(null, childData); | ||
if (!this.nodes[id]) | ||
this.create(id); | ||
this.nodes[id].exec(null, childData); | ||
} | ||
else { | ||
if (_this.nodes[id]) | ||
_this.nodes[id].destroy(); | ||
if (this.nodes[id]) | ||
this.nodes[id].destroy(); | ||
} | ||
} | ||
else { | ||
_.each(_this.nodes, function (childCursor, id) { | ||
var childData = bundle_1.get(newValue, id); | ||
_.each(this.nodes, (childCursor, id) => { | ||
const childData = bundle_1.get(newValue, id); | ||
if (!childData) | ||
@@ -49,6 +32,6 @@ childCursor.destroy(); | ||
}); | ||
_.each(newValue, function (childData, id) { | ||
if (!_this.nodes[id]) | ||
_this.create(id); | ||
_this.nodes[id].exec(null, bundle_1.get(newValue, id)); | ||
_.each(newValue, (childData, id) => { | ||
if (!this.nodes[id]) | ||
this.create(id); | ||
this.nodes[id].exec(null, bundle_1.get(newValue, id)); | ||
}); | ||
@@ -58,18 +41,12 @@ } | ||
}; | ||
}; | ||
return ChildsCursorsManager; | ||
}(superClass)); | ||
} | ||
}; | ||
} | ||
exports["default"] = mixin; | ||
exports.default = mixin; | ||
exports.mixin = mixin; | ||
var MixedChildsCursorsManager = mixin(cursors_manager_1.CursorsManager); | ||
const MixedChildsCursorsManager = mixin(cursors_manager_1.CursorsManager); | ||
exports.MixedChildsCursorsManager = MixedChildsCursorsManager; | ||
var ChildsCursorsManager = (function (_super) { | ||
__extends(ChildsCursorsManager, _super); | ||
function ChildsCursorsManager() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
return ChildsCursorsManager; | ||
}(MixedChildsCursorsManager)); | ||
class ChildsCursorsManager extends MixedChildsCursorsManager { | ||
} | ||
exports.ChildsCursorsManager = ChildsCursorsManager; | ||
//# sourceMappingURL=childs-cursors-manager.js.map |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
exports.__esModule = true; | ||
var _ = require("lodash"); | ||
var node_1 = require("ancient-mixins/lib/node"); | ||
var bundle_1 = require("./bundle"); | ||
function watch(_a, paths, listener) { | ||
var oldValue = _a.oldValue, newValue = _a.newValue, bundlePath = _a.bundlePath, data = _a.data, bundle = _a.bundle; | ||
var watchPath = _.toPath(bundle_1.toPath(data, paths)); | ||
var localWatchPath = watchPath.slice(bundlePath.length); | ||
var localBundlePath = bundlePath.slice(watchPath.length); | ||
var leastPathLength = Math.min(watchPath.length, bundlePath.length); | ||
var value = bundle_1.get(data, paths); | ||
var localOldValue; | ||
var localNewValue; | ||
var isClone; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const _ = require("lodash"); | ||
const node_1 = require("ancient-mixins/lib/node"); | ||
const bundle_1 = require("./bundle"); | ||
function watch({ oldValue, newValue, bundlePath, data, bundle }, paths, listener) { | ||
const watchPath = _.toPath(bundle_1.toPath(data, paths)); | ||
const localWatchPath = watchPath.slice(bundlePath.length); | ||
const localBundlePath = bundlePath.slice(watchPath.length); | ||
const leastPathLength = Math.min(watchPath.length, bundlePath.length); | ||
const value = bundle_1.get(data, paths); | ||
let localOldValue; | ||
let localNewValue; | ||
let isClone; | ||
if (leastPathLength) { | ||
@@ -41,6 +30,6 @@ if (!_.isEqual(watchPath.slice(0, leastPathLength), bundlePath.slice(0, leastPathLength))) { | ||
listener({ | ||
bundlePath: bundlePath, watchPath: watchPath, localBundlePath: localBundlePath, localWatchPath: localWatchPath, data: data, bundle: bundle, | ||
isClone: isClone, | ||
bundlePath, watchPath, localBundlePath, localWatchPath, data, bundle, | ||
isClone, | ||
oldValue: localOldValue, | ||
newValue: localNewValue | ||
newValue: localNewValue, | ||
}); | ||
@@ -50,14 +39,14 @@ } | ||
function apply(cursor, bundle) { | ||
var bundleChanges = cursor.parse(bundle); | ||
var oldValue = bundleChanges.oldValue, newValue = bundleChanges.newValue, bundlePath = bundleChanges.bundlePath, data = bundleChanges.data; | ||
var eventData = { | ||
data: data, | ||
oldValue: oldValue, | ||
newValue: newValue, | ||
bundlePath: bundlePath, | ||
bundle: bundle, | ||
cursor: cursor, | ||
watch: function (path, listener) { | ||
const bundleChanges = cursor.parse(bundle); | ||
const { oldValue, newValue, bundlePath, data } = bundleChanges; | ||
const eventData = { | ||
data, | ||
oldValue, | ||
newValue, | ||
bundlePath, | ||
bundle, | ||
cursor, | ||
watch: (path, listener) => { | ||
watch(bundleChanges, path, listener); | ||
} | ||
}, | ||
}; | ||
@@ -67,11 +56,7 @@ cursor.emit('changed', eventData); | ||
function mixin(superClass) { | ||
return (function (_super) { | ||
__extends(Cursor, _super); | ||
function Cursor() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
Cursor.prototype.exec = function (query, data) { | ||
var oldQuery = this.query; | ||
var oldData = this.data; | ||
var oldQueryId = this.queryId; | ||
return class Cursor extends node_1.Node { | ||
exec(query, data) { | ||
const oldQuery = this.query; | ||
const oldData = this.data; | ||
const oldQueryId = this.queryId; | ||
this.query = query; | ||
@@ -81,33 +66,27 @@ if (data) | ||
this.queryId = this.generateId(); | ||
this.emit('exec', { oldQuery: oldQuery, oldData: oldData, oldQueryId: oldQueryId, cursor: this }); | ||
this.emit('exec', { oldQuery, oldData, oldQueryId, cursor: this }); | ||
return this; | ||
}; | ||
Cursor.prototype.apply = function (bundle) { | ||
} | ||
apply(bundle) { | ||
apply(this, bundle); | ||
return this; | ||
}; | ||
Cursor.prototype.parse = function (bundle) { | ||
} | ||
parse(bundle) { | ||
if (!bundle_1.bundleParsers[bundle.type]) { | ||
throw new Error("Parser " + bundle.type + " is not founded."); | ||
throw new Error(`Parser ${bundle.type} is not founded.`); | ||
} | ||
return bundle_1.bundleParsers[bundle.type](this, bundle); | ||
}; | ||
Cursor.prototype.get = function (paths) { | ||
} | ||
get(paths) { | ||
return bundle_1.get(this.data, paths); | ||
}; | ||
return Cursor; | ||
}(node_1.Node)); | ||
} | ||
}; | ||
} | ||
exports["default"] = mixin; | ||
exports.default = mixin; | ||
exports.mixin = mixin; | ||
var MixedCursor = mixin(node_1.Node); | ||
const MixedCursor = mixin(node_1.Node); | ||
exports.MixedCursor = MixedCursor; | ||
var Cursor = (function (_super) { | ||
__extends(Cursor, _super); | ||
function Cursor() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
return Cursor; | ||
}(MixedCursor)); | ||
class Cursor extends MixedCursor { | ||
} | ||
exports.Cursor = Cursor; | ||
//# sourceMappingURL=cursor.js.map |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
exports.__esModule = true; | ||
var manager_1 = require("ancient-mixins/lib/manager"); | ||
var cursor_1 = require("./cursor"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const manager_1 = require("ancient-mixins/lib/manager"); | ||
const cursor_1 = require("./cursor"); | ||
function mixin(superClass) { | ||
return (function (_super) { | ||
__extends(CursorsManager, _super); | ||
function CursorsManager() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.Node = cursor_1.Cursor; | ||
return _this; | ||
return class CursorsManager extends superClass { | ||
constructor() { | ||
super(...arguments); | ||
this.Node = cursor_1.Cursor; | ||
} | ||
return CursorsManager; | ||
}(superClass)); | ||
}; | ||
} | ||
exports["default"] = mixin; | ||
exports.default = mixin; | ||
exports.mixin = mixin; | ||
var MixedCursorsManager = mixin(manager_1.Manager); | ||
const MixedCursorsManager = mixin(manager_1.Manager); | ||
exports.MixedCursorsManager = MixedCursorsManager; | ||
var CursorsManager = (function (_super) { | ||
__extends(CursorsManager, _super); | ||
function CursorsManager() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
return CursorsManager; | ||
}(MixedCursorsManager)); | ||
class CursorsManager extends MixedCursorsManager { | ||
} | ||
exports.CursorsManager = CursorsManager; | ||
//# sourceMappingURL=cursors-manager.js.map |
{ | ||
"name": "ancient-cursor", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Abstract container of data synchronization.", | ||
@@ -5,0 +5,0 @@ "bugs": "https://github.com/AncientSouls/Cursor/issues", |
"use strict"; | ||
exports.__esModule = true; | ||
var chai_1 = require("chai"); | ||
var bundle_1 = require("../lib/bundle"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chai_1 = require("chai"); | ||
const bundle_1 = require("../lib/bundle"); | ||
function default_1() { | ||
describe('Bundle:', function () { | ||
describe('paths', function () { | ||
it('path', function () { | ||
describe('Bundle:', () => { | ||
describe('paths', () => { | ||
it('path', () => { | ||
chai_1.assert.equal(bundle_1.get({ a: [{ b: [{ c: 'd' }] }] }, 'a.0.b.0.c'), 'd'); | ||
}); | ||
it('(path[]|find)[]', function () { | ||
it('(path[]|find)[]', () => { | ||
chai_1.assert.equal(bundle_1.get({ | ||
@@ -22,35 +22,35 @@ a: [ | ||
] }, | ||
] | ||
], | ||
}, ['a', { x: 7 }, 'b', ['y', 6], 'c']), 3); | ||
}); | ||
}); | ||
describe('types', function () { | ||
it('set', function () { | ||
var container = { data: { a: [{ b: { c: 123 } }] } }; | ||
describe('types', () => { | ||
it('set', () => { | ||
const container = { data: { a: [{ b: { c: 123 } }] } }; | ||
bundle_1.bundleParsers.set(container, { | ||
type: 'set', | ||
path: 'a.0.b.c', | ||
value: 234 | ||
value: 234, | ||
}); | ||
chai_1.assert.deepEqual(container.data, { a: [{ b: { c: 234 } }] }); | ||
}); | ||
it('extend', function () { | ||
var container = { data: { a: [{ b: { c: 123 } }] } }; | ||
it('extend', () => { | ||
const container = { data: { a: [{ b: { c: 123 } }] } }; | ||
bundle_1.bundleParsers.extend(container, { | ||
type: 'extend', | ||
path: 'a.0.b', | ||
value: { d: 234 } | ||
value: { d: 234 }, | ||
}); | ||
chai_1.assert.deepEqual(container.data, { a: [{ b: { c: 123, d: 234 } }] }); | ||
}); | ||
it('unset', function () { | ||
var container = { data: { a: [{ b: { c: 123 } }] } }; | ||
it('unset', () => { | ||
const container = { data: { a: [{ b: { c: 123 } }] } }; | ||
bundle_1.bundleParsers.unset(container, { | ||
type: 'unset', | ||
path: 'a.0.b.c' | ||
path: 'a.0.b.c', | ||
}); | ||
chai_1.assert.deepEqual(container.data, { a: [{ b: {} }] }); | ||
}); | ||
it('splice', function () { | ||
var container = { data: { a: [{ b: { c: 123 } }, { b: { c: 456 } }] } }; | ||
it('splice', () => { | ||
const container = { data: { a: [{ b: { c: 123 } }, { b: { c: 456 } }] } }; | ||
bundle_1.bundleParsers.splice(container, { | ||
@@ -64,3 +64,3 @@ type: 'splice', | ||
{ b: { c: 345 } }, | ||
] | ||
], | ||
}); | ||
@@ -74,4 +74,4 @@ chai_1.assert.deepEqual(container.data, { a: [ | ||
}); | ||
it('remove', function () { | ||
var container = { data: { x: [ | ||
it('remove', () => { | ||
const container = { data: { x: [ | ||
{ y: 1, a: [{ b: { c: 123 } }, { b: { c: 456 } }] }, | ||
@@ -83,3 +83,3 @@ { y: 2, a: [{ b: { c: 123 } }, { b: { c: 456 } }] }, | ||
path: ['x', ['y', 2], 'a'], | ||
selector: { b: { c: 123 } } | ||
selector: { b: { c: 123 } }, | ||
}); | ||
@@ -91,6 +91,31 @@ chai_1.assert.deepEqual(container.data, { x: [ | ||
}); | ||
it('push', () => { | ||
const container = { data: { x: [ | ||
{ y: 1, a: [{ b: { c: 123 } }, { b: { c: 456 } }] }, | ||
{ y: 2, a: [{ b: { c: 123 } }, { b: { c: 456 } }] }, | ||
] } }; | ||
bundle_1.bundleParsers.push(container, { | ||
type: 'push', | ||
path: ['x', ['y', 2], 'a'], | ||
value: [{ d: 567 }], | ||
}); | ||
chai_1.assert.deepEqual(container.data, { x: [ | ||
{ y: 1, a: [{ b: { c: 123 } }, { b: { c: 456 } }] }, | ||
{ y: 2, a: [{ b: { c: 123 } }, { b: { c: 456 } }, { d: 567 }] }, | ||
] }); | ||
}); | ||
it('move', () => { | ||
const container = { data: { x: [0, 1, 2, 3, 4, 5, 6] } }; | ||
bundle_1.bundleParsers.move(container, { | ||
type: 'move', | ||
path: ['x'], | ||
from: 3, | ||
to: 5, | ||
}); | ||
chai_1.assert.deepEqual(container.data, { x: [0, 1, 2, 4, 5, 3, 6] }); | ||
}); | ||
}); | ||
}); | ||
} | ||
exports["default"] = default_1; | ||
exports.default = default_1; | ||
//# sourceMappingURL=bundle.js.map |
"use strict"; | ||
exports.__esModule = true; | ||
var _ = require("lodash"); | ||
var chai_1 = require("chai"); | ||
var cursor_1 = require("../lib/cursor"); | ||
var childs_cursors_manager_1 = require("../lib/childs-cursors-manager"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const _ = require("lodash"); | ||
const chai_1 = require("chai"); | ||
const cursor_1 = require("../lib/cursor"); | ||
const childs_cursors_manager_1 = require("../lib/childs-cursors-manager"); | ||
function test(path) { | ||
var _path = path ? path + "." : path; | ||
var parent = new cursor_1.Cursor(); | ||
var ccm = new childs_cursors_manager_1.ChildsCursorsManager(); | ||
const _path = path ? `${path}.` : path; | ||
const parent = new cursor_1.Cursor(); | ||
const ccm = new childs_cursors_manager_1.ChildsCursorsManager(); | ||
parent.on('changed', ccm.maintain(path)); | ||
parent.apply({ | ||
type: 'set', | ||
path: "" + path, | ||
path: `${path}`, | ||
value: { | ||
a: { a: 1 }, | ||
b: { b: 2 }, | ||
c: { c: 3 } | ||
} | ||
c: { c: 3 }, | ||
}, | ||
}); | ||
chai_1.assert.deepEqual(_.get(parent.data, _path + "a"), ccm.nodes.a.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, _path + "b"), ccm.nodes.b.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, _path + "c"), ccm.nodes.c.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, `${_path}a`), ccm.nodes.a.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, `${_path}b`), ccm.nodes.b.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, `${_path}c`), ccm.nodes.c.data); | ||
parent.apply({ | ||
type: 'set', | ||
path: _path + "b.b", | ||
value: 4 | ||
path: `${_path}b.b`, | ||
value: 4, | ||
}); | ||
chai_1.assert.deepEqual(_.get(parent.data, _path + "a"), ccm.nodes.a.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, _path + "b"), { b: 4 }); | ||
chai_1.assert.deepEqual(_.get(parent.data, _path + "b"), ccm.nodes.b.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, _path + "c"), ccm.nodes.c.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, `${_path}a`), ccm.nodes.a.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, `${_path}b`), { b: 4 }); | ||
chai_1.assert.deepEqual(_.get(parent.data, `${_path}b`), ccm.nodes.b.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, `${_path}c`), ccm.nodes.c.data); | ||
parent.apply({ | ||
type: 'set', | ||
path: _path + "d.d", | ||
value: 5 | ||
path: `${_path}d.d`, | ||
value: 5, | ||
}); | ||
chai_1.assert.deepEqual(_.get(parent.data, _path + "a"), ccm.nodes.a.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, _path + "b"), ccm.nodes.b.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, _path + "c"), ccm.nodes.c.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, _path + "d"), { d: 5 }); | ||
chai_1.assert.deepEqual(_.get(parent.data, _path + "d"), ccm.nodes.d.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, `${_path}a`), ccm.nodes.a.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, `${_path}b`), ccm.nodes.b.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, `${_path}c`), ccm.nodes.c.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, `${_path}d`), { d: 5 }); | ||
chai_1.assert.deepEqual(_.get(parent.data, `${_path}d`), ccm.nodes.d.data); | ||
parent.apply({ | ||
type: 'unset', | ||
path: _path + "d" | ||
path: `${_path}d`, | ||
}); | ||
chai_1.assert.deepEqual(_.get(parent.data, _path + "a"), ccm.nodes.a.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, _path + "b"), ccm.nodes.b.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, _path + "c"), ccm.nodes.c.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, `${_path}a`), ccm.nodes.a.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, `${_path}b`), ccm.nodes.b.data); | ||
chai_1.assert.deepEqual(_.get(parent.data, `${_path}c`), ccm.nodes.c.data); | ||
chai_1.assert.isNotOk(ccm.nodes.d); | ||
} | ||
function default_1() { | ||
describe('ChildsCursorsManager:', function () { | ||
it('maintain ""', function () { | ||
describe('ChildsCursorsManager:', () => { | ||
it('maintain ""', () => { | ||
test(''); | ||
}); | ||
it('maintain "x"', function () { | ||
it('maintain "x"', () => { | ||
test('x'); | ||
}); | ||
it('maintain "x.y"', function () { | ||
it('maintain "x.y"', () => { | ||
test('x.y'); | ||
@@ -65,3 +65,3 @@ }); | ||
} | ||
exports["default"] = default_1; | ||
exports.default = default_1; | ||
//# sourceMappingURL=childs-cursors-manager.js.map |
"use strict"; | ||
exports.__esModule = true; | ||
var chai_1 = require("chai"); | ||
var cursor_1 = require("../lib/cursor"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chai_1 = require("chai"); | ||
const cursor_1 = require("../lib/cursor"); | ||
function default_1() { | ||
describe('Cursor:', function () { | ||
it('get()', function () { | ||
var cursor = new cursor_1.Cursor(); | ||
describe('Cursor:', () => { | ||
it('get()', () => { | ||
const cursor = new cursor_1.Cursor(); | ||
cursor.exec(true, { a: [{ b: { c: 'd' } }] }); | ||
chai_1.assert.equal(cursor.get('a.0.b.c'), 'd'); | ||
}); | ||
it('apply()', function () { | ||
var cursor = new cursor_1.Cursor(); | ||
it('apply()', () => { | ||
const cursor = new cursor_1.Cursor(); | ||
cursor.exec(true, { a: [{ b: { c: 'd' } }] }); | ||
@@ -18,11 +18,10 @@ cursor.apply({ | ||
path: 'a.0.b', | ||
value: { d: 'e' } | ||
value: { d: 'e' }, | ||
}); | ||
chai_1.assert.equal(cursor.get('a.0.b.d'), 'e'); | ||
}); | ||
it('changed', function (done) { | ||
var cursor = new cursor_1.Cursor(); | ||
it('changed', (done) => { | ||
const cursor = new cursor_1.Cursor(); | ||
cursor.exec(true, { a: [{ b: { c: 'd' } }] }); | ||
cursor.on('changed', function (_a) { | ||
var data = _a.data, oldValue = _a.oldValue, newValue = _a.newValue, bundlePath = _a.bundlePath, bundle = _a.bundle, watch = _a.watch, cursor = _a.cursor; | ||
cursor.on('changed', ({ data, oldValue, newValue, bundlePath, bundle, watch, cursor, }) => { | ||
chai_1.assert.deepEqual(data, { a: [{ b: { d: 'e' } }] }); | ||
@@ -36,13 +35,11 @@ chai_1.assert.deepEqual(oldValue, { c: 'd' }); | ||
path: 'a.0.b', | ||
value: { d: 'e' } | ||
value: { d: 'e' }, | ||
}); | ||
}); | ||
it('watch', function (done) { | ||
var cursor = new cursor_1.Cursor(); | ||
it('watch', (done) => { | ||
const cursor = new cursor_1.Cursor(); | ||
cursor.exec(true, { a: [{ b: { c: 'd' } }] }); | ||
cursor.on('changed', function (_a) { | ||
var watch = _a.watch; | ||
var counter = 0; | ||
watch('', function (_a) { | ||
var isClone = _a.isClone, oldValue = _a.oldValue, newValue = _a.newValue; | ||
cursor.on('changed', ({ watch }) => { | ||
let counter = 0; | ||
watch('', ({ isClone, oldValue, newValue }) => { | ||
chai_1.assert.isFalse(isClone); | ||
@@ -53,4 +50,3 @@ chai_1.assert.deepEqual(oldValue, { a: [{ d: { e: 'f' } }] }); | ||
}); | ||
watch('a', function (_a) { | ||
var isClone = _a.isClone, oldValue = _a.oldValue, newValue = _a.newValue; | ||
watch('a', ({ isClone, oldValue, newValue }) => { | ||
chai_1.assert.isFalse(isClone); | ||
@@ -61,4 +57,3 @@ chai_1.assert.deepEqual(oldValue, [{ d: { e: 'f' } }]); | ||
}); | ||
watch('a.0', function (_a) { | ||
var isClone = _a.isClone, oldValue = _a.oldValue, newValue = _a.newValue; | ||
watch('a.0', ({ isClone, oldValue, newValue }) => { | ||
chai_1.assert.isTrue(isClone); | ||
@@ -69,4 +64,3 @@ chai_1.assert.deepEqual(oldValue, { b: { c: 'd' } }); | ||
}); | ||
watch(['a', {}, 'b'], function (_a) { | ||
var isClone = _a.isClone, oldValue = _a.oldValue, newValue = _a.newValue; | ||
watch(['a', {}, 'b'], ({ isClone, oldValue, newValue }) => { | ||
chai_1.assert.isTrue(isClone); | ||
@@ -77,4 +71,3 @@ chai_1.assert.deepEqual(oldValue, { c: 'd' }); | ||
}); | ||
watch('a.0.b', function (_a) { | ||
var isClone = _a.isClone, oldValue = _a.oldValue, newValue = _a.newValue; | ||
watch('a.0.b', ({ isClone, oldValue, newValue }) => { | ||
chai_1.assert.isTrue(isClone); | ||
@@ -85,4 +78,3 @@ chai_1.assert.deepEqual(oldValue, { c: 'd' }); | ||
}); | ||
watch('a.0.b.c', function (_a) { | ||
var isClone = _a.isClone, oldValue = _a.oldValue, newValue = _a.newValue; | ||
watch('a.0.b.c', ({ isClone, oldValue, newValue }) => { | ||
chai_1.assert.isTrue(isClone); | ||
@@ -93,4 +85,3 @@ chai_1.assert.deepEqual(oldValue, 'd'); | ||
}); | ||
watch('a.0.d', function (_a) { | ||
var isClone = _a.isClone, oldValue = _a.oldValue, newValue = _a.newValue; | ||
watch('a.0.d', ({ isClone, oldValue, newValue }) => { | ||
chai_1.assert.isTrue(isClone); | ||
@@ -101,4 +92,3 @@ chai_1.assert.deepEqual(oldValue, undefined); | ||
}); | ||
watch('a.0.d.e', function (_a) { | ||
var isClone = _a.isClone, oldValue = _a.oldValue, newValue = _a.newValue; | ||
watch('a.0.d.e', ({ isClone, oldValue, newValue }) => { | ||
chai_1.assert.isTrue(isClone); | ||
@@ -109,12 +99,9 @@ chai_1.assert.deepEqual(oldValue, undefined); | ||
}); | ||
watch('x.y.z', function (_a) { | ||
var isClone = _a.isClone, oldValue = _a.oldValue, newValue = _a.newValue; | ||
watch('x.y.z', ({ isClone, oldValue, newValue }) => { | ||
throw new Error('"x.y.z" path is not changed, wrong watch calling'); | ||
}); | ||
watch('a.1', function (_a) { | ||
var isClone = _a.isClone, oldValue = _a.oldValue, newValue = _a.newValue; | ||
watch('a.1', ({ isClone, oldValue, newValue }) => { | ||
throw new Error('"a.1" path is not changed, wrong watch calling'); | ||
}); | ||
watch('b', function (_a) { | ||
var isClone = _a.isClone, oldValue = _a.oldValue, newValue = _a.newValue; | ||
watch('b', ({ isClone, oldValue, newValue }) => { | ||
throw new Error('"b" path is not changed, wrong watch calling'); | ||
@@ -128,3 +115,3 @@ }); | ||
path: 'a.0', | ||
value: { d: { e: 'f' } } | ||
value: { d: { e: 'f' } }, | ||
}); | ||
@@ -134,3 +121,3 @@ }); | ||
} | ||
exports["default"] = default_1; | ||
exports.default = default_1; | ||
//# sourceMappingURL=cursor.js.map |
"use strict"; | ||
exports.__esModule = true; | ||
var chai_1 = require("chai"); | ||
var cursors_manager_1 = require("../lib/cursors-manager"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chai_1 = require("chai"); | ||
const cursors_manager_1 = require("../lib/cursors-manager"); | ||
function default_1() { | ||
describe('CursorsManager:', function () { | ||
it('changed', function (done) { | ||
var cursorsManager = new cursors_manager_1.CursorsManager(); | ||
var cursor = cursorsManager.create(); | ||
describe('CursorsManager:', () => { | ||
it('changed', (done) => { | ||
const cursorsManager = new cursors_manager_1.CursorsManager(); | ||
const cursor = cursorsManager.create(); | ||
cursor.exec(true, { a: [{ b: { c: 'd' } }] }); | ||
cursorsManager.on('changed', function (_a) { | ||
var data = _a.data, oldValue = _a.oldValue, newValue = _a.newValue, bundlePath = _a.bundlePath, bundle = _a.bundle, watch = _a.watch, cursor = _a.cursor, manager = _a.manager; | ||
cursorsManager.on('changed', ({ data, oldValue, newValue, bundlePath, bundle, watch, cursor, manager, }) => { | ||
chai_1.assert.deepEqual(data, { a: [{ b: { d: 'e' } }] }); | ||
@@ -21,3 +20,3 @@ chai_1.assert.deepEqual(oldValue, { c: 'd' }); | ||
path: 'a.0.b', | ||
value: { d: 'e' } | ||
value: { d: 'e' }, | ||
}); | ||
@@ -27,3 +26,3 @@ }); | ||
} | ||
exports["default"] = default_1; | ||
exports.default = default_1; | ||
//# sourceMappingURL=cursors-manager.js.map |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require('source-map-support').install(); | ||
var bundle_1 = require("./bundle"); | ||
var cursor_1 = require("./cursor"); | ||
var cursors_manager_1 = require("./cursors-manager"); | ||
var childs_cursors_manager_1 = require("./childs-cursors-manager"); | ||
describe('AncientSouls/Cursor:', function () { | ||
bundle_1["default"](); | ||
cursor_1["default"](); | ||
cursors_manager_1["default"](); | ||
childs_cursors_manager_1["default"](); | ||
const bundle_1 = require("./bundle"); | ||
const cursor_1 = require("./cursor"); | ||
const stackable_cursor_1 = require("./stackable-cursor"); | ||
const cursors_manager_1 = require("./cursors-manager"); | ||
const childs_cursors_manager_1 = require("./childs-cursors-manager"); | ||
describe('AncientSouls/Cursor:', () => { | ||
bundle_1.default(); | ||
cursor_1.default(); | ||
stackable_cursor_1.default(); | ||
cursors_manager_1.default(); | ||
childs_cursors_manager_1.default(); | ||
}); | ||
//# sourceMappingURL=index.js.map |
@@ -8,3 +8,4 @@ { | ||
"declaration": true, | ||
"outDir": "./" | ||
"outDir": "./", | ||
"target": "es6" | ||
}, | ||
@@ -11,0 +12,0 @@ "include": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71399
39
888