mobx-keystone
Version:
A MobX powered state management solution based on data trees with first class support for TypeScript, snapshots, patches and much more
18 lines (14 loc) • 422 B
text/typescript
import { namespace } from "../../utils"
import { ActionCallArgumentSerializer, cannotSerialize } from "./core"
export const dateSerializer: ActionCallArgumentSerializer<Date, number> = {
id: `${namespace}/dateAsTimestamp`,
serialize(date) {
if (!(date instanceof Date)) {
return cannotSerialize
}
return +date
},
deserialize(timestamp) {
return new Date(timestamp)
},
}