Skip to content

Commit

Permalink
fix: Added support for gawking objects with symbol keys.
Browse files Browse the repository at this point in the history
fix(gulp): Fixed lint task to stop when error occurs.
chore(lint): Set no-debugger rule to warning.
chore: Updated npm deps.
  • Loading branch information
cb1kenobi committed Apr 5, 2019
1 parent cdd84de commit bef9101
Show file tree
Hide file tree
Showing 7 changed files with 830 additions and 778 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"chai-expect/missing-assertion": "error",
"chai-expect/terminating-properties": "warn",
"curly": [ "error", "all" ],
"no-debugger": "warn",
"eol-last": "error",
"indent": [ "error", "tab", { "SwitchCase": 1 } ],
"keyword-spacing": [ "error" ],
Expand Down
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ exports.clean = parallel(cleanCoverage, cleanDist, cleanDocs);
/*
* lint tasks
*/
async function lint(pattern) {
function lint(pattern) {
return gulp.src(pattern)
.pipe($.plumber())
.pipe($.eslint())
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"gulp-load-plugins": "^1.5.0",
"gulp-plumber": "^1.2.1",
"gulp-sourcemaps": "^2.6.4",
"mocha": "^5.2.0",
"mocha": "^6.0.2",
"nyc": "^13.1.0",
"sinon": "^7.2.2",
"sinon-chai": "^3.3.0"
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export default function gawk(value, parent) {
});

// gawk any object properties
for (const key of Object.getOwnPropertyNames(gawked)) {
for (const key of Reflect.ownKeys(gawked)) {
if (key !== '__gawk__' && gawked[key] && typeof gawked[key] === 'object') {
gawked[key] = gawk(gawked[key], gawked);
}
Expand Down
15 changes: 15 additions & 0 deletions test/test-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ describe('gawk() object', () => {
expect(isGawked(gobj)).to.be.true;
});

it('should gawk object with symbol keys', () => {
const s = Symbol();
const gobj = gawk({
foo: {
name: 'foo!'
},
[s]: {
name: 'symbol!'
}
});
expect(isGawked(gobj)).to.be.true;
expect(gobj.foo).to.deep.equal({ name: 'foo!' });
expect(gobj[s]).to.deep.equal({ name: 'symbol!' });
});

it('should not allow __gawk__ to be set', () => {
const gobj = gawk({});
expect(isGawked(gobj)).to.be.true;
Expand Down
21 changes: 21 additions & 0 deletions test/test-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,4 +669,25 @@ describe('gawk.unwatch()', () => {
expect(callback).to.be.calledOnce;
expect(gobj.foo).to.equal('BAZ');
});

it('should notify when a symbol property value changes', () => {
const s = Symbol();
const gobj = gawk({
foo: {
name: 'foo'
},
[s]: {
name: 'symbol'
}
});
const callback = spy();

gawk.watch(gobj, callback);

gobj.foo.name = 'foo!';
expect(callback).to.be.calledOnce;

gobj[s].name = 'symbol!';
expect(callback).to.be.calledTwice;
});
});
Loading

0 comments on commit bef9101

Please sign in to comment.