Skip to content

Commit

Permalink
v4.4.0
Browse files Browse the repository at this point in the history
Added the super cool gawk.set() function for replacing an existing object with a new one.

Fixed the gulp task for esdoc generation.

Updated NPM deps.
  • Loading branch information
cb1kenobi committed Oct 28, 2017
1 parent 99d70c2 commit dcca58b
Show file tree
Hide file tree
Showing 9 changed files with 978 additions and 632 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ node_js:
os: linux
sudo: false
before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 0.27.5
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.2.1
- export PATH=$HOME/.yarn/bin:$PATH
cache:
yarn: true
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016-2017 Chris Barber
Copyright (c) 2016-2017 Chris Barber and Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
64 changes: 39 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
[![Deps][david-image]][david-url]
[![Dev Deps][david-dev-image]][david-dev-url]

Gawk wraps JavaScript objects and arrays making them observable. Once a JavaScript object is gawked,
you can listen for changes including deeply nested changes. Only objects and arrays can be gawked.
All other types are passed through.
Gawk wraps JavaScript objects and arrays using ES2015 proxies making them observable. Once a
JavaScript object (or array) is gawked, you can listen for changes including deeply nested changes.

Only objects and arrays can be gawked. All other types are passed through.

Gawked objects and arrays can be interacted with as if they were regular objects/arrays. Built-in
functions such as `JSON.stringify()` work as expected.
Expand All @@ -18,7 +19,7 @@ functions such as `JSON.stringify()` work as expected.
## Installation

npm install gawk
npm i --save gawk

## Examples

Expand Down Expand Up @@ -93,6 +94,26 @@ gawk.unwatch(obj, onChange);
obj.foo = 'baz'; // does not fire onChange()
```

To update an object and preserve the listeners, you can use the `gawk.set()` function.

```javascript
const obj = gawk({
foo: 'bar'
});

gawk.watch(obj, () => {
console.log('changed!');
});

gawk.set(obj, { baz: 'wiz' });

console.log(obj); // { baz: 'wiz' }

obj.baz = 'wow';

console.log(obj); // { baz: 'wow' }
```

## API

### `gawk(obj)`
Expand All @@ -116,6 +137,19 @@ Determines if an variable is a gawked object.

Returns `true` if the specified object has been gawked, otherwise `false`

### `gawk.set(dest, src)`

### `gawk.set(dest, src, compareFn)`

Replaces the entire definition of a gawked object with another object or array while preserving any
listeners and dispatches change nofications afterwards.

* `dest` - (Object|Array) The destination object. It will be automatically gawked if not already.
* `src` - (Object|Array) The source object or array to copy from.
* `compareFn` - (Function) An optional function to call when comparing elements of an array.

Returns the original `dest` object.

### `gawk.watch(subject, listener)`

### `gawk.watch(subject, filter, listener)`
Expand Down Expand Up @@ -210,27 +244,7 @@ than v1 and v2.

## License

(The MIT License)

Copyright (c) 2016-2017 Chris Barber

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
MIT

[npm-image]: https://img.shields.io/npm/v/gawk.svg
[npm-url]: https://npmjs.org/package/gawk
Expand Down
39 changes: 27 additions & 12 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,33 @@ gulp.task('build', ['clean-dist', 'lint-src'], function () {
.pipe(gulp.dest(distDir));
});

gulp.task('docs', ['lint-src', 'clean-docs'], function () {
return gulp.src('src')
.pipe($.plumber())
.pipe($.debug({ title: 'docs' }))
.pipe($.esdoc({
// debug: true,
destination: docsDir,
plugins: [
{ name: 'esdoc-es7-plugin' }
],
title: manifest.name
}));
gulp.task('docs', ['clean-docs'], () => {
const esdoc = require('esdoc').default;

esdoc.generate({
// debug: true,
destination: docsDir,
plugins: [
{
name: 'esdoc-standard-plugin',
option: {
brand: {
title: manifest.name,
description: manifest.description,
respository: 'https://github.com/cb1kenobi/gawk',
site: 'https://github.com/cb1kenobi/gawk'
}
}
},
{
name: 'esdoc-ecmascript-proposal-plugin',
option: {
all: true
}
}
],
source: './src'
});
});

/*
Expand Down
27 changes: 15 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gawk",
"version": "4.3.0",
"version": "4.4.0",
"description": "Observable JavaScript object model",
"main": "./dist/index.js",
"author": "Chris Barber <[email protected]> (https://github.com/cb1kenobi)",
Expand All @@ -19,38 +19,41 @@
"build": "gulp build",
"coverage": "gulp coverage",
"docs": "gulp docs",
"prepublish": "gulp build",
"prepare": "gulp build",
"test": "gulp test"
},
"dependencies": {
"source-map-support": "^0.4.16"
"babel-core": "^6.26.0",
"esdoc": "^1.0.3",
"esdoc-ecmascript-proposal-plugin": "^1.0.0",
"esdoc-standard-plugin": "^1.0.0",
"source-map-support": "^0.5.0"
},
"devDependencies": {
"babel-eslint": "^7.2.3",
"babel-plugin-istanbul": "^4.1.4",
"babel-eslint": "^8.0.1",
"babel-plugin-istanbul": "^4.1.5",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-plugin-transform-es2015-parameters": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-register": "^6.26.0",
"chai": "^4.1.1",
"coveralls": "^2.13.1",
"chai": "^4.1.2",
"coveralls": "^3.0.0",
"del": "^3.0.0",
"esdoc-es7-plugin": "^0.0.3",
"eslint-plugin-security": "^1.4.0",
"gulp": "^3.9.1",
"gulp-babel": "^7.0.0",
"gulp-debug": "^3.1.0",
"gulp-esdoc": "^0.4.1",
"gulp-eslint": "^4.0.0",
"gulp-load-plugins": "^1.5.0",
"gulp-plumber": "^1.1.0",
"gulp-util": "^3.0.8",
"mocha": "^3.5.0",
"nyc": "^11.1.0",
"sinon": "^3.2.1",
"sinon-chai": "^2.13.0"
"mocha": "^4.0.1",
"nyc": "^11.2.1",
"sinon": "^4.0.2",
"sinon-chai": "^2.14.0"
},
"homepage": "https://github.com/cb1kenobi/gawk",
"bugs": "https://github.com/cb1kenobi/gawk/issues",
Expand Down
Loading

0 comments on commit dcca58b

Please sign in to comment.