Skip to content

nju33/gsw

Repository files navigation

gsw

get, set, watch

github npm:version typescript ci:status Coverage Status document:typedoc license browserslist code style: prettier

Usage

/**
 * To prepare of using the `gsw`
 * ```sh
 * yarn add gsw
 * ```
 */
import gsw from 'gsw';

or

<script src="https://unpkg.com/gsw/gsw.js"></script>
<script>
  // Can use the `gsw` here.
</script>

Example

const value = gsw({
  foo: 'str',
  bar: 123,
  baz: true
});

// get
expect(value('foo')).toBe('str');

// set
value('bar', 456);
expect(value('bar')).toBe(456);

// listener
value('baz', (newValue, oldValue) => {
  console.log(`newValue: ${newValue}, oldValue: ${oldValue}`);
});
value('baz', false);
// newValue: false, oldValue: true
value('baz', false);
value('baz', true);
// newValue: true, oldValue: false

Edit @gsw/example