Skip to content

Instantly share code, notes, and snippets.

@cowboyd
Created February 8, 2020 22:49
Show Gist options
  • Select an option

  • Save cowboyd/f64f39810330125f4b22ef5651481fa5 to your computer and use it in GitHub Desktop.

Select an option

Save cowboyd/f64f39810330125f4b22ef5651481fa5 to your computer and use it in GitHub Desktop.
A microstate email form which stores its original value
class EmailForm {
original = {};
fields = {};
initialize(value) {
if (!value) {
return {original: {}, fields: {}};
}
if (!value.fields) {
return this.reset();
}
return value;
}
get isDirty() {
return valueOf(this.original) !== valueOf(this.fields);
}
setEmail(value) {
return this.fields.put('email', value);
}
setPassword(value) {
return this.fields.put('password', value);
}
clear() {
return this.fields.set(this.original);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment