Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update with-mobx-keystone-typescript example #10638

Merged
merged 1 commit into from Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -16,9 +16,7 @@ const Clock: FC<Props> = props => {
font: '50px menlo, monaco, monospace',
padding: '15px',
}
return (
<div style={divStyle}>{format(new Date(props.lastUpdate as number))}</div>
)
return <div style={divStyle}>{format(props.lastUpdate)}</div>
}

export { Clock }
2 changes: 1 addition & 1 deletion examples/with-mobx-keystone-typescript/package.json
Expand Up @@ -8,7 +8,7 @@
},
"dependencies": {
"mobx": "^5.15.1",
"mobx-keystone": "^0.30.0",
"mobx-keystone": "^0.41.0",
"mobx-react-lite": "^1.5.2",
"next": "latest",
"react": "^16.12.0",
Expand Down
15 changes: 9 additions & 6 deletions examples/with-mobx-keystone-typescript/store/root.ts
@@ -1,16 +1,19 @@
import { Model, model, prop, modelAction, timestampAsDate } from 'mobx-keystone'
import {
Model,
model,
prop,
modelAction,
prop_dateTimestamp,
} from 'mobx-keystone'

@model('store/root')
class RootStore extends Model({
foo: prop<number | null>(0),
lastUpdate: prop<number | null>(new Date().getTime()),
lastUpdate: prop_dateTimestamp(() => new Date()),
light: prop(false),
}) {
timer!: ReturnType<typeof setInterval>

@timestampAsDate('lastUpdate')
lastUpdateDate!: Date

@modelAction
start() {
this.timer = setInterval(() => {
Expand All @@ -19,7 +22,7 @@ class RootStore extends Model({
}
@modelAction
update() {
this.lastUpdate = Date.now()
this.lastUpdate = new Date()
this.light = true
}

Expand Down