PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.1
JetFormBuilder — Dynamic Blocks Form Builder v3.1.1
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / assets / src / frontend / main / reactive / ReactiveVar.js
jetformbuilder / assets / src / frontend / main / reactive Last commit date
LoadingReactiveVar.js 2 years ago ReactiveHook.js 2 years ago ReactiveSet.js 2 years ago ReactiveVar.js 2 years ago
ReactiveVar.js
115 lines
1 import { isEmpty } from '../functions';
2
3 function ReactiveVar( value = null ) {
4 this.current = value;
5 this.signals = [];
6 this.sanitizers = [];
7 this.isDebug = false;
8 this.isSilence = false;
9 this.isMaked = false;
10 }
11
12 ReactiveVar.prototype = {
13 watchOnce: function ( callable ) {
14 if ( 'function' !== typeof callable ) {
15 return;
16 }
17 const clearWatcher = this.watch( () => {
18 clearWatcher();
19 callable();
20 } );
21 },
22 watch: function ( callable ) {
23 if ( 'function' !== typeof callable ) {
24 return false;
25 }
26
27 if ( this.signals.some( ( { signal } ) => signal === callable ) ) {
28 return true;
29 }
30
31 this.signals.push( {
32 signal: callable,
33 trace: new Error().stack,
34 } );
35
36 const index = this.signals.length - 1;
37
38 return () => this.signals.splice( index, 1 );
39 },
40 sanitize: function ( callable ) {
41 if ( 'function' !== typeof callable ) {
42 return false;
43 }
44
45 if ( -1 !== this.sanitizers.indexOf( callable ) ) {
46 return true;
47 }
48
49 this.sanitizers.push( callable );
50
51 const index = this.sanitizers.length - 1;
52
53 return () => this.sanitizers.splice( index, 1 );
54 },
55 make: function () {
56 if ( this.isMaked ) {
57 return;
58 }
59 this.isMaked = true;
60 let current = this.current;
61 let prevValue = null;
62 const self = this;
63
64 Object.defineProperty( this, 'current', {
65 get() {
66 return current;
67 },
68 set( newVal ) {
69 if ( current === newVal ) {
70 return;
71 }
72 prevValue = current;
73 if ( self.isDebug ) {
74 console.group( 'ReactiveVar has changed' );
75 console.log( 'current:', current );
76 console.log( 'newVal:', newVal );
77 console.groupEnd();
78 debugger;
79 }
80 current = self.applySanitizers( newVal );
81
82 if ( self.isSilence ) {
83 return;
84 }
85 self.notify( prevValue );
86 },
87 } );
88 },
89 notify: function ( prevValue = null ) {
90 this.signals.forEach(
91 ( { signal } ) => signal.call( this, prevValue ) );
92 },
93 applySanitizers: function ( value ) {
94 for ( const sanitizer of this.sanitizers ) {
95 value = sanitizer.call( this, value );
96 }
97
98 return value;
99 },
100 setIfEmpty( newValue ) {
101 if ( !isEmpty( this.current ) ) {
102 return;
103 }
104
105 this.current = newValue;
106 },
107 debug() {
108 this.isDebug = !this.isDebug;
109 },
110 silence() {
111 this.isSilence = !this.isSilence;
112 },
113 };
114
115 export default ReactiveVar;