mobx-keystone icon indicating copy to clipboard operation
mobx-keystone copied to clipboard

[Poll] Time for v1.0.0?

Open xaviergonz opened this issue 5 years ago • 15 comments

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 avatar Sep 22 '19 20:09 xaviergonz

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

xaviergonz avatar Sep 22 '19 20:09 xaviergonz

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.

sisp avatar Sep 23 '19 06:09 sisp

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

xaviergonz avatar Sep 23 '19 11:09 xaviergonz

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.

sisp avatar Sep 23 '19 17:09 sisp

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

xaviergonz avatar Sep 23 '19 18:09 xaviergonz

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 ...)

sisp avatar Sep 23 '19 18:09 sisp

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

xaviergonz avatar Sep 23 '19 19:09 xaviergonz

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?

terrysahaidak avatar Sep 26 '19 12:09 terrysahaidak

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 avatar Sep 26 '19 18:09 xaviergonz

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

xaviergonz avatar Sep 26 '19 21:09 xaviergonz

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

terrysahaidak avatar Sep 28 '19 21:09 terrysahaidak

Published prop transforms as 0.23.0

xaviergonz avatar Oct 02 '19 17:10 xaviergonz

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

swayf avatar Mar 20 '20 18:03 swayf

Time for v1.0.0? =)))

swayf avatar Mar 21 '20 08:03 swayf

May be Jan 01 2021 ?

alex-shamshurin avatar Dec 05 '20 09:12 alex-shamshurin