que-proxyable
TypeScript icon, indicating that this package has built-in type declarations

1.1.6 • Public • Published

que-proxyable 使用说明

一个简单的使用 proxy 代理对象的库,并能够进行监听。

简单使用

import { Proxyable, ProxyWatcher } from 'que-proxyable';
const data = Proxyable({ a: 100 });
const watcher = new ProxyWatch();
const unsub = watcher.onGet((t, k) => console.log(t, k));
data.a = 1000; // print value of t and k
unsub();
data.a = 2000; // print nothing

进阶使用

State

import { State, ProxyWatcher } from 'que-proxyable';
class A {
  @State()
  count = 1;
}
const watcher = new ProxyWatcher();
watcher.onGet((t, k) => console.log(k));
const a = new A();
a.count;
// k's value count will print

Compute

import { State, Compute } from 'que-proxyable';
class A {
  @State()
  count = 1;

  age = 1;

  @Compute()
  show() {
    this.age++;
    return this.count;
  }
}
const a = new A();
a.show();
console.log(a.age); // 2
a.show();
console.log(a.age); // still 2
a.count++;
console.log(a.age); // still 2
a.show();
console.log(a.age); // 3

Readme

Keywords

none

Package Sidebar

Install

npm i que-proxyable

Weekly Downloads

0

Version

1.1.6

License

ISC

Unpacked Size

24.7 kB

Total Files

20

Last publish

Collaborators

  • zxqian1991