LoadingReactiveVar.js
2 years ago
ReactiveHook.js
2 years ago
ReactiveSet.js
2 years ago
ReactiveVar.js
2 years ago
ReactiveHook.js
26 lines
| 1 | function ReactiveHook() { |
| 2 | this.handlers = []; |
| 3 | } |
| 4 | |
| 5 | ReactiveHook.prototype = { |
| 6 | addFilter( callable ) { |
| 7 | this.handlers.push( callable ); |
| 8 | |
| 9 | const index = this.handlers.length - 1; |
| 10 | |
| 11 | return () => this.handlers.splice( index, 1 ); |
| 12 | }, |
| 13 | applyFilters( ...params ) { |
| 14 | let current = params[ 0 ]; |
| 15 | const newParams = params.slice( 1 ); |
| 16 | |
| 17 | for ( const handler of this.handlers ) { |
| 18 | current = handler( current, ...newParams ); |
| 19 | } |
| 20 | |
| 21 | return current; |
| 22 | }, |
| 23 | }; |
| 24 | |
| 25 | export default ReactiveHook; |
| 26 |