UNPKG

com-tools

Version:

com-tools 提供了一些通用的工具函数;

198 lines (87 loc) 2.66 kB
<!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [com-tools](./com-tools.md) &gt; [Decide](./com-tools.decide.md) ## Decide class 决议 用来监听决议的值; 当 决议时,会自动回调所有注册的事件,并回传决议的值;决议之后,再进行监听,监听事件会被立即被回调,并传递决议的值; 说明: 功能类似 Promise,也可用 Promise 来更轻松地实现,但之所以不用 Promise ,是因为 Promise 的回调是异步的,但我想同步回调,即让回调在一个运行循环内完成; 与 Promise 的区别是: - then回调是在 决议时 和 决议之后 同步执行的;并会回传最新的 this.value - 简单、轻量 - 通过给 Decide 实例的 value 属性设置值 `decide.value = newValue` 自动触发决议; - 即使决议之后,你也可以更改 value 的值,但不会再触发之添加的事件监听器; **Signature:** ```typescript export declare class Decide<V = any> ``` ## Properties <table><thead><tr><th> Property </th><th> Modifiers </th><th> Type </th><th> Description </th></tr></thead> <tbody><tr><td> [\_decided](./com-tools.decide._decided.md) </td><td> `protected` </td><td> boolean </td><td> </td></tr> <tr><td> [\_value](./com-tools.decide._value.md) </td><td> `protected` </td><td> V </td><td> </td></tr> <tr><td> [decided](./com-tools.decide.decided.md) </td><td> `readonly` </td><td> boolean </td><td> </td></tr> <tr><td> [listeners](./com-tools.decide.listeners.md) </td><td> </td><td> ((copy: V) =&gt; void)\[\] </td><td> </td></tr> <tr><td> [value](./com-tools.decide.value.md) </td><td> </td><td> V </td><td> </td></tr> </tbody></table> ## Methods <table><thead><tr><th> Method </th><th> Modifiers </th><th> Description </th></tr></thead> <tbody><tr><td> [resolve()](./com-tools.decide.resolve.md) </td><td> `protected` </td><td> 执行回调,并且为了提高性能,会让决议之后的 then 方法直接执行回调 </td></tr> <tr><td> [resolve(value)](./com-tools.decide.resolve.md) </td><td> `static` </td><td> 创建一个直接决议的 Decide,并且决议的值是 value </td></tr> <tr><td> [then(cb)](./com-tools.decide.then.md) </td><td> </td><td> 监听决议,当被决议后,会自动回调 cb,并回传最新的 this.value </td></tr> </tbody></table>