Skip to content

Commit

Permalink
REVERT update-functions by hand
Browse files Browse the repository at this point in the history
  • Loading branch information
pubkey committed May 22, 2017
1 parent 14046bf commit 5c623c7
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 102 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
"deep-equal": "^1.0.1",
"es6-promise": "^4.0.5",
"is-my-json-valid": "^2.16.0",
"modifyjs": "^0.3.1",
"object-path": "0.11.4",
"pouchdb-core": "6.2.0",
"pouchdb-find": "6.2.0",
Expand Down
12 changes: 0 additions & 12 deletions src/RxCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,6 @@ class RxCollection {
}
}

/**
* updates an object with a mongolike syntax
* @param {object} queryObj
* @param {object} updateObj
*/

async update(queryObj, updateObj) {
const docs = await this.find(queryObj).exec();
for (let doc of docs)
await doc.update(updateObj);
}

/**
* takes a mongoDB-query-object and returns the documents
* @param {object} queryObj
Expand Down
28 changes: 0 additions & 28 deletions src/RxDocument.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import clone from 'clone';
import objectPath from 'object-path';
import deepEqual from 'deep-equal';
import modify from 'modifyjs';

import * as util from './util';
import * as RxChangeEvent from './RxChangeEvent';
Expand Down Expand Up @@ -251,33 +250,6 @@ class RxDocument {
return this;
};

/**
* updates document
* @param {object} updateObj
*/
async update(updateObj) {
const newDoc = modify(this._data, updateObj);

Object.keys(this._data).forEach((previousPropName) => {
if (newDoc[previousPropName]) {
// if we don't check inequality, it triggers an update attempt on fields that didn't really change,
// which causes problems with "readonly" fields
if (!deepEqual(this[previousPropName], newDoc[previousPropName]))
this[previousPropName] = newDoc[previousPropName];

} else
delete this[previousPropName];

});
delete newDoc._rev;
delete newDoc._id;
Object.keys(newDoc).forEach(newPropName => {
if (!deepEqual(this[newPropName], newDoc[newPropName]))
this[newPropName] = newDoc[newPropName];
});
await this.save();
}

/**
* save document if its data has changed
* @return {boolean} false if nothing to save
Expand Down
18 changes: 0 additions & 18 deletions src/RxQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,24 +305,6 @@ class RxQuery {
return docs;
}

/**
* updates all found documents
* @param {object} updateObj
* @return {Promise(RxDocument|RxDocument[])} promise with updated documents
*/
async update(updateObj) {
const docs = await this.exec();
if (Array.isArray(docs)) {
await Promise.all(
docs.map(doc => doc.update(updateObj))
);
} else {
// via findOne()
await docs.update(updateObj);
}
return docs;
}

async exec() {
return await this.$
.first()
Expand Down
3 changes: 0 additions & 3 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ declare class RxCollection {
upsert(json: any): Promise<RxDocument>;
find(queryObj?: any): RxQuery;
findOne(queryObj?: any): RxQuery;
update(queryObj: any, updateObj: any): Promise<any>;

dump(decrytped: boolean): Promise<any>;
importDump(exportedJSON: any): Promise<Boolean>;
Expand Down Expand Up @@ -176,7 +175,6 @@ declare class RxQuery {
exec(): Promise<RxDocument[]>;
$: Observable<RxDocument[]>;
remove(): Promise<RxDocument | RxDocument[]>;
update(updateObj: any): Promise<RxDocument|RxDocument[]>;
}

declare class RxDocument {
Expand All @@ -195,7 +193,6 @@ declare class RxDocument {
save(): Promise<boolean>;
remove(): Promise<boolean>;
populate(objPath: string): Promise<RxDocument |null>;
update(updateObj: any): Promise<any>;

toJSON(): Object;
destroy(): void;
Expand Down
19 changes: 0 additions & 19 deletions test/unit/RxCollection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,15 +360,6 @@ describe('RxCollection.test.js', () => {
});
});
});
describe('.update()', () => {
it('should update all documents matched by a query', async() => {
const c = await humansCollection.create();
await c.update({}, {$set: {firstName: 'new first name'}});
const docs = await c.find().exec();
for (let doc of docs)
assert.equal(doc._data.firstName, 'new first name');
});
});
describe('.find()', () => {
describe('find all', () => {
describe('positive', () => {
Expand Down Expand Up @@ -807,16 +798,6 @@ describe('RxCollection.test.js', () => {
assert.equal(docsAfter.length, 9);
});
});
describe('.update()', () => {
it('should update all documents', async() => {
const c = await humansCollection.create(10);
const query = c.find();
const updated = await query.update({$set: {firstName: 'new first name'}});
const docsAfterUpdate = await c.find().exec();
for (let doc of docsAfterUpdate)
assert.equal(doc._data.firstName, 'new first name');
});
});
});
describe('.findOne()', () => {
describe('positive', () => {
Expand Down
21 changes: 0 additions & 21 deletions test/unit/RxDocument.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,27 +261,6 @@ describe('RxDocument.test.js', () => {
});
});
});
describe('update', () => {
it('a value with a mongo like query', async() => {
const c = await humansCollection.createPrimary(1);
const doc = await c.findOne().exec();
await doc.update({$set: {firstName: 'new first name'}});
const updatedDoc = await c.findOne({firstName: 'new first name'}).exec();
assert.equal(updatedDoc.firstName, 'new first name');
});

it('unset a value', async() => {
const c = await humansCollection.createPrimary(1);
const doc = await c.findOne().exec();
await doc.update({
$unset: {
firstName: ''
}
});
const updatedDoc = await c.findOne().exec();
assert.equal(updatedDoc.firstName, undefined);
});
});
describe('pseudo-Proxy', () => {
describe('get', () => {
it('top-value', async() => {
Expand Down

0 comments on commit 5c623c7

Please sign in to comment.