Unverified Commit 18ecaa9d authored by Evgeniy Kumachev's avatar Evgeniy Kumachev Committed by GitHub

Update with-mobx-keystone-typescript example (#10638)

parent 156a7740
...@@ -16,9 +16,7 @@ const Clock: FC<Props> = props => { ...@@ -16,9 +16,7 @@ const Clock: FC<Props> = props => {
font: '50px menlo, monaco, monospace', font: '50px menlo, monaco, monospace',
padding: '15px', padding: '15px',
} }
return ( return <div style={divStyle}>{format(props.lastUpdate)}</div>
<div style={divStyle}>{format(new Date(props.lastUpdate as number))}</div>
)
} }
export { Clock } export { Clock }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
}, },
"dependencies": { "dependencies": {
"mobx": "^5.15.1", "mobx": "^5.15.1",
"mobx-keystone": "^0.30.0", "mobx-keystone": "^0.41.0",
"mobx-react-lite": "^1.5.2", "mobx-react-lite": "^1.5.2",
"next": "latest", "next": "latest",
"react": "^16.12.0", "react": "^16.12.0",
......
import { Model, model, prop, modelAction, timestampAsDate } from 'mobx-keystone' import {
Model,
model,
prop,
modelAction,
prop_dateTimestamp,
} from 'mobx-keystone'
@model('store/root') @model('store/root')
class RootStore extends Model({ class RootStore extends Model({
foo: prop<number | null>(0), foo: prop<number | null>(0),
lastUpdate: prop<number | null>(new Date().getTime()), lastUpdate: prop_dateTimestamp(() => new Date()),
light: prop(false), light: prop(false),
}) { }) {
timer!: ReturnType<typeof setInterval> timer!: ReturnType<typeof setInterval>
@timestampAsDate('lastUpdate')
lastUpdateDate!: Date
@modelAction @modelAction
start() { start() {
this.timer = setInterval(() => { this.timer = setInterval(() => {
...@@ -19,7 +22,7 @@ class RootStore extends Model({ ...@@ -19,7 +22,7 @@ class RootStore extends Model({
} }
@modelAction @modelAction
update() { update() {
this.lastUpdate = Date.now() this.lastUpdate = new Date()
this.light = true this.light = true
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment