Skip to content

Commit

Permalink
v4.6.6
Browse files Browse the repository at this point in the history
fix: Symbol property support.
  • Loading branch information
cb1kenobi committed Oct 31, 2019
1 parent ab698c1 commit a00d21a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gawk",
"version": "4.6.5",
"version": "4.6.6",
"description": "Observable JavaScript object model",
"main": "./dist/index.js",
"author": "Chris Barber <[email protected]> (https://github.com/cb1kenobi)",
Expand Down
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ function copyListeners(dest, src, compareFn) {
return;
}

for (const key of Object.getOwnPropertyNames(dest)) {
for (const key of [ ...Object.getOwnPropertySymbols(dest), ...Object.getOwnPropertyNames(dest) ]) {
if (key === '__gawk__') {
continue;
}
Expand Down Expand Up @@ -500,7 +500,7 @@ export function set(dest, src, compareFn) {

const tmp = {};

for (const key of Object.getOwnPropertyNames(src)) {
for (const key of [ ...Object.getOwnPropertySymbols(src), ...Object.getOwnPropertyNames(src) ]) {
if (key === '__gawk__') {
continue;
}
Expand All @@ -519,7 +519,7 @@ export function set(dest, src, compareFn) {
}

// prune the existing object, then copy all the properties from our temp object
for (const key of Object.getOwnPropertyNames(dest)) {
for (const key of [ ...Object.getOwnPropertySymbols(dest), ...Object.getOwnPropertyNames(dest) ]) {
if (key !== '__gawk__') {
delete dest[key];
}
Expand Down Expand Up @@ -682,7 +682,7 @@ function mix(objs, deep) {
* @param {Object} src - The source object to copy from.
*/
const mixer = (gobj, src) => {
for (const key of Object.getOwnPropertyNames(src)) {
for (const key of [ ...Object.getOwnPropertySymbols(src), ...Object.getOwnPropertyNames(src) ]) {
if (key === '__gawk__') {
continue;
}
Expand Down
30 changes: 22 additions & 8 deletions test/test-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,12 @@ describe('set property', () => {

const gobj = gawk({});
gobj[id] = 'foo';
expect(gobj).to.deep.equal({ [id]: 'foo' });
expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([ id ]);
expect(gobj[id]).to.equal('foo');

gobj[id] = 'bar';
expect(gobj).to.deep.equal({ [id]: 'bar' });
expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([ id ]);
expect(gobj[id]).to.equal('bar');
});
});

Expand Down Expand Up @@ -296,13 +298,22 @@ describe('Object.keys()', () => {
});

describe('Object.getOwnPropertySymbols()', () => {
it('should return an array of symbol keys in the object', () => {
it('should return an array of symbol keys in empty object', () => {
const id = Symbol();

const gobj = gawk({ [id]: 'foo' });
expect(gobj).to.deep.equal({ [id]: 'foo' });
const gobj = gawk({});
expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([]);

gobj[id] = 'foo';
expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([ id ]);
});

it('should return an array of symbol keys from initialized object', () => {
const id = Symbol();

const gobj = gawk({ [id]: 'foo' });
expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([ id ]);
expect(gobj[id]).to.equal('foo');
});
});

Expand Down Expand Up @@ -396,11 +407,14 @@ describe('gawk.merge()', () => {
it('should merge an object with a symbol property', () => {
const id = Symbol();

const gobj = gawk({ [id]: 'foo' });
expect(gobj).to.deep.equal({ [id]: 'foo' });
const gobj = gawk({});
gobj[id] = 'foo';
expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([ id ]);
expect(gobj[id]).to.equal('foo');

gawk.merge(gobj, { [id]: 'bar' });
expect(gobj).to.deep.equal({ [id]: 'bar' });
expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([ id ]);
expect(gobj[id]).to.equal('bar');
});
});

Expand Down
18 changes: 15 additions & 3 deletions test/test-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,25 @@ describe('gawk.set()', () => {
expect(counter).to.equal(2);
});

it('should set an object with a symbol property', () => {
it('should set an existing object with a symbol property', () => {
const id = Symbol();

const gobj = gawk({});

gawk.set(gobj, { [id]: 'foo' });
expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([ id ]);
expect(gobj[id]).to.equal('foo');
});

it('should set an existing object with a symbol property', () => {
const id = Symbol();

const gobj = gawk({ [id]: 'foo' });
expect(gobj).to.deep.equal({ [id]: 'foo' });
expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([ id ]);
expect(gobj[id]).to.equal('foo');

gawk.set(gobj, { [id]: 'bar' });
expect(gobj).to.deep.equal({ [id]: 'bar' });
expect(Object.getOwnPropertySymbols(gobj)).to.deep.equal([ id ]);
expect(gobj[id]).to.equal('bar');
});
});

0 comments on commit a00d21a

Please sign in to comment.