Skip to content

Commit

Permalink
FIX #4949 RxDocument.get() on additonalProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
pubkey committed Oct 4, 2023
1 parent 6e45127 commit 1f0a1a7
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs-src/releases/15.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ I will add more p2p replication plugins in the future, which are not based on [W

## Improve RxDocument property access performance

We now use the Proxy API instead of defining getters on each nested property.
We now use the Proxy API instead of defining getters on each nested property. Also fixed [#4949](https://github.com/pubkey/rxdb/pull/4949)
1 change: 1 addition & 0 deletions orga/performance-trackings.md
Original file line number Diff line number Diff line change
Expand Up @@ -1535,3 +1535,4 @@ BEFORE:
AFTER:
"property-access": 4.71
"property-access": 5.14
"property-access": 5.07
2 changes: 1 addition & 1 deletion src/rx-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export const basePrototype = {
*/
flatClone(valueObj),
{
get(target, property) {
get(target, property: any) {
if (typeof property !== 'string') {
return target[property];
}
Expand Down
72 changes: 71 additions & 1 deletion test/unit/rx-document.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
addRxPlugin,
RxCollection,
createBlob,
defaultHashSha256
defaultHashSha256,
RxJsonSchema
} from '../../plugins/core';


Expand Down Expand Up @@ -1112,6 +1113,75 @@ describe('rx-document.test.js', () => {
}
}).remove();

// clean up afterwards
db.destroy();
});
it('#4949 RxDocument.get() on additonalProperty', async () => {
const mySchema: RxJsonSchema<any> = {
version: 0,
primaryKey: 'passportId',
type: 'object',
properties: {
passportId: {
type: 'string',
maxLength: 100
},
firstName: {
type: 'string'
},
lastName: {
type: 'string'
},
age: {
type: 'integer',
minimum: 0,
maximum: 150
},
tags: {
type: 'object',
additionalProperties: true,
},
},
};
const db = await createRxDatabase({
name: randomCouchString(10),
storage: config.storage.getStorage()
});
const collections = await db.addCollections({
mycollection: {
schema: mySchema
}
});
const tags = {
hello: {
created: 1,
name: 'hello',
},
world: {
created: 2,
name: 'world',
}
};
const myDocument = await collections.mycollection.insert({
passportId: 'foobar',
firstName: 'Bob',
lastName: 'Kelso',
age: 56,
tags
});

assert.deepStrictEqual(myDocument.toJSON().tags.hello, tags.hello, 'myDocument.toJSON().tags.hello');
assert.deepStrictEqual(myDocument.toJSON().tags.world, tags.world, 'myDocument.toJSON().tags.world');
assert.deepStrictEqual(Object.keys(myDocument.toJSON().tags), Object.keys(tags), 'Object.keys(myDocument.toJSON().tags)');
assert.deepStrictEqual(myDocument.get('tags').hello, tags.hello, 'myDocument.get(\'tags\').hello');

assert.deepStrictEqual(myDocument.get('tags').world, tags.world, 'myDocument.get(\'tags\').world');
assert.deepStrictEqual(Object.keys(myDocument.get('tags')), Object.keys(tags), 'Object.keys(myDocument.get(\'tags\'))');

assert.deepStrictEqual(myDocument.tags.hello, tags.hello, 'myDocument.tags.hello');
assert.deepStrictEqual(myDocument.tags.world, tags.world, 'myDocument.tags.world');
assert.deepStrictEqual(Object.keys(myDocument.tags), Object.keys(tags), 'Object.keys(myDocument.tags)');

// clean up afterwards
db.destroy();
});
Expand Down

0 comments on commit 1f0a1a7

Please sign in to comment.