Skip to content

Commit

Permalink
Merge pull request #40 from bjornstar/noMoreHiding
Browse files Browse the repository at this point in the history
v0.1.0 - No more hiding
  • Loading branch information
Ron Korving committed Nov 19, 2014
2 parents b3f7d74 + 00e4e0b commit 50762e4
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 180 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language:
- node_js
node_js:
- "0.11"
- "0.10"
- "0.8"
before_install:
Expand Down
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#Tomes Release Notes

##0.1.0
* Removed the hide method, it was useless and only increased code complexity.
* Added nodei.co badge.
* Added node v0.11 back to travis, maybe it will work now.
* unset executable bit from files.

##0.0.22
* inc now takes NumberTomes
* Added this `HISTORY.md` file
Expand Down
Empty file modified LICENSE
100755 → 100644
Empty file.
Empty file modified Makefile
100755 → 100644
Empty file.
5 changes: 2 additions & 3 deletions README.md
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![NPM](https://nodei.co/npm/tomes.png?downloads=true)](https://nodei.co/npm/tomes/)

[![Build Status](https://travis-ci.org/Wizcorp/node-tomes.png)](https://travis-ci.org/Wizcorp/node-tomes)

Tomes
Expand Down Expand Up @@ -91,9 +93,6 @@ Rename key to newkey.
###move( *key*, *tome*, [ *newkey* ] )
Move key to tome. Optionally call it newkey on that tome.

###hide( [ *boolean* ] )
Hides a Tome. The Tome still exists in this tome, but will neither stringify nor show up in any events. Shows up as a delete in change operations.

###read( )
Get a single change operation from the root Tome, removing it in the process. Returns null if there are no changes.

Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "tomes",
"repo": "Wizcorp/node-tomes",
"description": "Evented Storage Agnostic Data API",
"version": "0.0.22",
"version": "0.1.0",
"keywords": [ "data", "events" ],
"dependencies": {
"component/emitter": "*"
Expand Down
106 changes: 12 additions & 94 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,13 @@ function Tome(parent, key) {
// __key__ is the key that our Tome is referred to by its parent. It only
// exists on Tomes with parents.

// __hidden__ is a boolean indicating whether or not a Tome's value should
// be hidden from toJSON and event emission. It exists on all Tomes.

// If you're using the node.js event emitter, we need to make the _events
// non-enumerable. Ideally, node.js would make this the default behavior.

var hasParentTome = Tome.isTome(parent);

var properties = {
__dirty__: { writable: true, value: 1 },
__hidden__: { writable: true, value: false },
__root__: { writable: true, value: hasParentTome ? parent.__root__ : this },
_events: { configurable: true, writable: true },
_callbacks: { configurable: true, writable: true }
Expand All @@ -103,34 +99,18 @@ function Tome(parent, key) {
}

function emitAdd(tome, key) {
if (tome.__hidden__) {
return;
}

tome.emit('add', key);
}

function emitDel(tome, key) {
if (tome.__hidden__) {
return;
}

tome.emit('del', key);
}

function emitDestroy(tome) {
if (tome.__hidden__) {
return;
}

tome.emit('destroy');
}

function destroy(tome) {
if (tome.__hidden__) {
return;
}

// When a Tome is deleted we emit a destroy event on it and all of its child
// Tomes since they will no longer exist. We go down the Tome chain first and
// then emit our way up.
Expand Down Expand Up @@ -269,9 +249,7 @@ function markDirty(tome, dirtyAt, was) {

tome.__dirty__ = dirtyAt;

if (!tome.__hidden__) {
tome.emit('readable', was);
}
tome.emit('readable', was);

if (tome.hasOwnProperty('__parent__')) {
markDirty(tome.__parent__, dirtyAt);
Expand Down Expand Up @@ -575,10 +553,6 @@ function conjure(val, parent, key, seen) {
// inherited. This is also how we pass parent into our Tome so we can signal
// a parent that its child has been modified.

if (Tome.isTome(val) && val.__hidden__) {
return;
}

var vType = Tome.typeOf(val);
var ClassRef = tomeMap[vType];
var vInit = initMap[vType];
Expand Down Expand Up @@ -975,10 +949,6 @@ Tome.prototype.merge = function (diff) {
// merge is used to apply diffs to our Tomes. Typically the diff would be a
// parsed JSON string or come directly from another Tome.

if (this.__hidden__) {
throw new Error('Tome.merge - Cannot merge to hidden Tomes.');
}

var diffs = Tome.typeOf(diff) === 'array' ? diff : [ diff ];

for (var i = 0, len = diffs.length; i < len; i += 1) {
Expand Down Expand Up @@ -1085,24 +1055,6 @@ Tome.prototype.swap = function (key, target) {
return this;
};

Tome.prototype.hide = function (h) {
if (h === undefined) {
h = true;
}

if (this.__hidden__ === h) {
return;
}

this.__hidden__ = h;

if (h) {
diff(this.__parent__, 'del', this.__key__);
} else {
diff(this.__parent__, 'set', { key: this.__key__, val: this.valueOf() });
}
};


// ______
// / \
Expand All @@ -1127,15 +1079,11 @@ ArrayTome.isArrayTome = function (o) {
};

ArrayTome.prototype.valueOf = function () {
if (!this.__hidden__) {
return this._arr || [];
}
return this._arr || [];
};

ArrayTome.prototype.toJSON = function () {
if (!this.__hidden__) {
return this._arr || [];
}
return this._arr || [];
};

ArrayTome.prototype.typeOf = function () {
Expand Down Expand Up @@ -1633,15 +1581,11 @@ BooleanTome.prototype.typeOf = function () {
};

BooleanTome.prototype.valueOf = function () {
if (!this.__hidden__) {
return this._val;
}
return this._val;
};

BooleanTome.prototype.toJSON = function () {
if (!this.__hidden__) {
return this._val;
}
return this._val;
};


Expand All @@ -1665,15 +1609,11 @@ NullTome.isNullTome = function (o) {
};

NullTome.prototype.valueOf = function () {
if (!this.__hidden__) {
return null;
}
return null;
};

NullTome.prototype.toJSON = function () {
if (!this.__hidden__) {
return null;
}
return null;
};

NullTome.prototype.typeOf = function () {
Expand Down Expand Up @@ -1736,15 +1676,11 @@ NumberTome.prototype.typeOf = function () {
};

NumberTome.prototype.valueOf = function () {
if (!this.__hidden__) {
return this._val;
}
return this._val;
};

NumberTome.prototype.toJSON = function () {
if (!this.__hidden__) {
return this._val;
}
return this._val;
};

NumberTome.prototype.toLocaleString = function () {
Expand Down Expand Up @@ -1829,18 +1765,6 @@ ObjectTome.prototype.rename = function () {
return this;
};

ObjectTome.prototype.valueOf = function () {
if (!this.__hidden__) {
return this;
}
};

ObjectTome.prototype.toJSON = function () {
if (!this.__hidden__) {
return this;
}
};


// ______ __ __
// / \ | \ | \
Expand Down Expand Up @@ -1873,15 +1797,11 @@ StringTome.prototype.typeOf = function () {
};

StringTome.prototype.valueOf = function () {
if (!this.__hidden__) {
return this._val;
}
return this._val;
};

StringTome.prototype.toJSON = function () {
if (!this.__hidden__) {
return this._val;
}
return this._val;
};


Expand Down Expand Up @@ -1919,9 +1839,7 @@ UndefinedTome.prototype.toJSON = function () {
// the behavior of JavaScript. That is the sole reason for UndefinedTome's
// existence.

if (!this.__hidden__) {
return null;
}
return null;
};

var classMap = {
Expand Down
Empty file modified logo/tomes-logo-big.png
100755 → 100644
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified logo/tomes-logo-less-big.png
100755 → 100644
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified logo/tomes-logo-medium.png
100755 → 100644
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified logo/tomes-logo-small.png
100755 → 100644
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tomes",
"description": "Evented Storage Agnostic Data API",
"version": "0.0.22",
"version": "0.1.0",
"author": "Wizcorp, Inc. <info@wizcorp.jp>",
"maintainers": [
{ "name": "Bjorn Stromberg", "email": "bstromberg@wizcorp.jp" }
Expand Down
34 changes: 5 additions & 29 deletions test/modules/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ exports.testDiffSimpleString = function (test) {
var a = 'asdf';
var b = Tome.conjure(a);
var c = Tome.conjure(a);

b.on('readable', function () {
var diff = b.read();
c.merge(diff);
});

a = 'fdsa';
b.assign('fdsa');

Expand Down Expand Up @@ -323,30 +323,6 @@ exports.testDiffSplice = function (test) {
test.done();
};

exports.testDiffHide = function (test) {
test.expect(2);

var a = [ { foo: 0, bar: 1 } ];
var b = Tome.conjure(a);
var c = Tome.conjure(a);

b.on('readable', function () {
var diff = b.read();
c.merge(diff);
});

delete a[0].foo;
a[0].bar += 1;

b[0].foo.inc().inc().inc().inc().set('hi', 0).hide();
b[0].bar.inc();

test.deepEqual(JSON.parse(JSON.stringify(a)), JSON.parse(JSON.stringify(b)));
test.deepEqual(JSON.parse(JSON.stringify(b)), JSON.parse(JSON.stringify(c)));

test.done();
};

exports.testDiffRenameCombine = function (test) {
test.expect(2);

Expand Down Expand Up @@ -642,7 +618,7 @@ exports.testDiffReverse = function (test) {

test.deepEqual(JSON.parse(JSON.stringify(a)), JSON.parse(JSON.stringify(b)));
test.deepEqual(JSON.parse(JSON.stringify(b)), JSON.parse(JSON.stringify(c)));

test.done();
};

Expand Down Expand Up @@ -684,13 +660,13 @@ exports.testDiffAssignReverse = function (test) {

a[0] = 10;
b[0].assign(10);

a.reverse();
b.reverse();

test.deepEqual(JSON.parse(JSON.stringify(a)), JSON.parse(JSON.stringify(b)));
test.deepEqual(JSON.parse(JSON.stringify(b)), JSON.parse(JSON.stringify(c)));

test.done();
};

Expand Down

0 comments on commit 50762e4

Please sign in to comment.