xaviergonz / mobx-keystone

A MobX powered state management solution based on data trees with first class support for Typescript, support for snapshots, patches and much more
https://mobx-keystone.js.org
MIT License
554 stars 25 forks source link

[Poll] Time for v1.0.0? #38

Open xaviergonz opened 5 years ago

xaviergonz commented 5 years ago

After the latest PR to remove "$" from paths I don't foresee big changes to the API for the time being. Also most issues seem to have been resolved now. Do you think it is time to brand it as v1.0.0?

xaviergonz commented 5 years ago

Well, actually there might be one more to add a better way to do async actions like in here: https://github.com/mobxjs/mobx/pull/2118 but it depends on this mobx PR being accepted: https://github.com/mobxjs/mobx/pull/2117

sisp commented 5 years ago

I have been thinking whether it makes sense to add a utility function findParentPath in addition to findParent which also returns the path of the found parent like in RootPath.

xaviergonz commented 5 years ago

Wouldn't that be the same as running getRootPath over the result?

sisp commented 5 years ago

No, I meant that findParentPath may return the parent object and the path from the parent object to the source object from which findParentPath begins its search, similar to getParentPath but with depth ≥ 1.

xaviergonz commented 5 years ago

Ah, sounds good :) https://github.com/xaviergonz/mobx-keystone/pull/43

sisp commented 5 years ago

About backrefs: Shouldn't the return type of getRefsResolvingTo be a readonly ObservableSet<Ref<T>>? (Not sure if that's possible by the way because MobX doesn't seem to have a ReadonlyObservableSet type ...)

xaviergonz commented 5 years ago

It should, but there are no readonly versions of observable stuff in mobx types :(

terrysahaidak commented 5 years ago

Didn't find any mention of custom types in docs, @xaviergonz. Simple case: My server responds with a timestamp as a date, I'm converting it into regular Date object in js, and converting back into the timestamp for snapshots. In MST I've used to use types.custom to address it. Is there something similar in mobx-keystone?

xaviergonz commented 5 years ago

There's none at the moment, but in theory you could have something like

class ... extends Model({timestamp: prop<number>()}) {
  @computed
  get date() { return new Date(this.timestamp) }

  @modelAction
  setDate(date: Date) { this.timestamp = +date }
}

I think there could be a way to extract this into a composable pattern (not working code):

const asDate = (getter: () => number, setter: (ts: number) => void) => {
  return {
    get: computed(() => new Date(getter())),
    set: modelAction((d: Date) => { setter(+d) })
  }
}

class ... {
  date = asDate(() => this.timestamp, (ts) => { this.timestamp = ts })
}

which maybe in turn could be simplified into something like

const asDate = dataTransform((ts) => new Date(ts), (date) => +date)

class ...  extends Model({ timestamp: prop<number>() }) {
  @asDate("timestamp")
  date!: Date
}

const date = model.date
model.date = new Date()

// or

class ...  extends Model({ timestamp: prop<number>() }) {
  date = asDate(this, "timestamp")
}

const date = model.date.get()
model.date.set(new Date())

would something like that be good enough for custom types? (which syntax btw, the decorator or the func one?)

xaviergonz commented 5 years ago

Just created a PR with the idea: https://github.com/xaviergonz/mobx-keystone/pull/48

terrysahaidak commented 5 years ago

I'm ok with decorator I think. This is a pretty general approach allows creating complex custom types.

xaviergonz commented 5 years ago

Published prop transforms as 0.23.0

swayf commented 4 years ago

Does it mean asyncAction from mobx-utils can be used just instead modelFlow?? =) or modelFlow still has something specific for the keystone?

swayf commented 4 years ago

Time for v1.0.0? =)))

alex-shamshurin commented 3 years ago

May be Jan 01 2021 ?