
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
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.
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.
Note: gawk uses ES2015 proxies and thus requires Node.js 6 or newer.
npm install gawk
import gawk from 'gawk';
const obj = gawk({
foo: 'bar'
});
gawk.watch(obj, (obj, src) => {
console.info('object changed!');
console.info('new value =', obj);
});
obj.foo = 'baz';
console.info(obj); // { foo: 'baz' }
You can also be notified if a deep child is changed:
const obj = gawk({
foo: {
bar: ['a', 'b']
}
});
gawk.watch(obj, (obj, src) => {
console.info('object changed!');
console.info('new value =', obj);
});
obj.foo.bar.push('c', 'd');
console.info(obj); // { foo: { bar: ['a', 'b', 'c', 'd'] } }
To filter watch notifications, simply pass in the property name or array of property names used to filter the gawk object.
const obj = gawk({
foo: {
bar: 'hello'
}
});
gawk.watch(obj, [ 'foo', 'bar' ], value => {
console.info(`bar changed to ${value}`);
});
obj.foo.bar = 'world!';
To stop watching, simply call gawk.unwatch()
with the original listener function.
const obj = gawk({ /* ... */ });
function onChange(obj, src) {
console.log('changed!');
}
gawk.watch(obj, onChange);
obj.foo = 'bar';
gawk.unwatch(obj, onChange);
obj.foo = 'baz'; // does not fire onChange()
Gawk v4 has dropped all gawk data types. You must always call gawk()
.
Change all new GawkObject()
calls to gawk({})
and new GawkArray()
to gawk([])
.
Since Gawk v3 and newer uses ES6 Proxies, you no longer need to call obj.get()
, obj.set()
,
obj.delete()
, etc.
Methods obj.watch()
, obj.merge()
, and obj.mergeDeep()
have moved to gawk.watch()
,
gawk.merge()
, and gawk.mergeDeep()
. The first argument must be a gawk object.
Starting in v3, Gawk no longer hashes values. This means speed. Gawk v3+ is about 19 times faster than v1 and v2.
(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.
FAQs
Observable JavaScript object model
The npm package gawk receives a total of 22 weekly downloads. As such, gawk popularity was classified as not popular.
We found that gawk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.