Skip to content

Commit

Permalink
FIX #75 populate-getter in property-list
Browse files Browse the repository at this point in the history
  • Loading branch information
pubkey committed Mar 12, 2017
1 parent 5876e85 commit 5dbe535
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
27 changes: 17 additions & 10 deletions src/RxDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,21 @@ class RxDocument {
return this.get(util.trimDots(objPath + '.' + key));
});
// getter - observable$
valueObj.__defineGetter__(key + '$', () => {
return this.get$(util.trimDots(objPath + '.' + key));
Object.defineProperty(valueObj, key + '$', {
get: () => {
return this.get$(util.trimDots(objPath + '.' + key));
},
enumerable: false,
configurable: false
});
// getter - populate_
valueObj.__defineGetter__(key + '_', () => {
return this.populate(util.trimDots(objPath + '.' + key));
Object.defineProperty(valueObj, key + '_', {
get: () => {
return this.populate(util.trimDots(objPath + '.' + key));
},
enumerable: false,
configurable: false
});

// setter - value
valueObj.__defineSetter__(key, (val) => {
return this.set(util.trimDots(objPath + '.' + key), val);
Expand Down Expand Up @@ -293,11 +300,11 @@ class RxDocument {
await this.collection.pouch.remove(this.getPrimary(), this._data._rev);

this.$emit(RxChangeEvent.create(
'REMOVE',
this.collection.database,
this.collection,
this,
null
'REMOVE',
this.collection.database,
this.collection,
this,
null
));

await this.collection._runHooks('post', 'remove', this);
Expand Down
10 changes: 6 additions & 4 deletions test/unit/RxDocument.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ describe('RxDocument.test.js', () => {
const passportId = doc.get('passportId');
assert.equal(doc.passportId, passportId);
});
it('hidden properties should not show up', async() => {
const c = await humansCollection.create(1);
const doc = await c.findOne().exec();
assert.ok(!Object.keys(doc).includes('lastName_'));
});
it('nested-value', async() => {
const c = await humansCollection.createNested(1);
const doc = await c.findOne().exec();
Expand Down Expand Up @@ -436,12 +441,11 @@ describe('RxDocument.test.js', () => {
const c = await humansCollection.createPrimary(0);
const docData = schemaObjects.simpleHuman();
const primary = docData.passportId;
console.dir(docData);


// insert
await c.insert(docData);
const doc1 = await c.findOne(primary).exec();
console.dir(doc1);
assert.equal(doc1.firstName, docData.firstName);

// remove
Expand All @@ -459,12 +463,10 @@ describe('RxDocument.test.js', () => {
const c = await humansCollection.createPrimary(0);
const docData = schemaObjects.simpleHuman();
const primary = docData.passportId;
console.dir(docData);

// insert
await c.upsert(docData);
const doc1 = await c.findOne(primary).exec();
console.dir(doc1);
assert.equal(doc1.firstName, docData.firstName);

// remove
Expand Down

0 comments on commit 5dbe535

Please sign in to comment.