Skip to content

Instantly share code, notes, and snippets.

@SaulDoesCode
Last active November 11, 2015 20:19
Show Gist options
  • Save SaulDoesCode/0f91273b9ba090714741 to your computer and use it in GitHub Desktop.
Save SaulDoesCode/0f91273b9ba090714741 to your computer and use it in GitHub Desktop.
class ReactiveVariable {
constructor(val, handle) {
if(typeof handle === 'function') {
this.Value = val;
this.Handle = handle;
} else console.error('ReactiveVariable needs a handler function after the value');
return this.Value;
}
set(val) {
if(this.Value !== val) {
this.Oldval = this.Value;
this.Value = val;
this.Handle(this.Oldval,val);
}
return this.Value;
}
Reset(handle) {
if(typeof handle === 'function') {
this.Handle = handle;
} else console.error('ReactiveVariable.Reset only takes a function');
}
}
@SaulDoesCode
Copy link
Author

Tiny Data Bind System that uses handlers and manual setting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment