-
-
Save dcolthorp/bba38d3522f08043ef757e36cf7fa3a2 to your computer and use it in GitHub Desktop.
This file contains 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
type CounterParams = { | |
value?: number, | |
status?: Status, | |
}; | |
export class Counter extends Record({ value: 0, status: OK }) { | |
value: number; | |
status: Status; | |
constructor(params?: CounterParams) { | |
params ? super(params) : super(); | |
} | |
with(values: CounterParams) { | |
return this.merge(values) as this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that the
CounterParams
type has all fields as optional. This is so we can construct or update aCounter
with a subset of the fields, relying on the defaults passed toRecord
to supply the rest.