Skip to content

Instantly share code, notes, and snippets.

@dcolthorp
Created October 7, 2016 17:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dcolthorp/bba38d3522f08043ef757e36cf7fa3a2 to your computer and use it in GitHub Desktop.
Save dcolthorp/bba38d3522f08043ef757e36cf7fa3a2 to your computer and use it in GitHub Desktop.
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;
}
}
@dcolthorp
Copy link
Author

Note that the CounterParams type has all fields as optional. This is so we can construct or update a Counter with a subset of the fields, relying on the defaults passed to Record to supply the rest.

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