Created
February 8, 2020 22:49
-
-
Save cowboyd/f64f39810330125f4b22ef5651481fa5 to your computer and use it in GitHub Desktop.
A microstate email form which stores its original value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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