Closed chengjianhua closed 6 years ago
In mobx-state-tree the frozen
type is used for this, which basically means: use this value verbatim in (de)serialization. I think something like that could work here as well (frozen
might not be the best name though)
@mweststrate So the suggestion you give is to add a type like frozen
to cover this requirement ?
Fine, it's not a bad idea. Maybe we can name this type json
( intuitive 🙄 ) or direct
and so on ...
@chengjianhua what about a plain
type? The issue with frozen is that it's not actually frozen. As far as a json
type, I would expect that this could be used with something that isn't actual json, like if you have a date or something that you don't want deconstruct.
@alexggordon Sorry for replying to you lately ... It's seems that we have reachd a consensus that we need such a type.
Now that you expect that this type could be used for not only json, but also a date ( means Date()
? ) and something others, what about we name this raw
. I think this is semantic enough to understand it and use it in many cases.
If you think this is ok, I'm happy to have a pull request for this.
Actually I do like the raw
better than plain
. That's a good word.
And sure, if you want to PR should be pretty easy. It's just primitive without validations I think.
@alexggordon Yep ~ you are right 👍
I have implemented this in my project ...
merged in f5d6ac3
@alexggordon We'd need this exact feature too. Could you please give us an estimate on when you're planning to push a new release? Thank you.
@cervengoc I'll deploy the new version right now
@cervengoc I've published the raw type in version 1.2.0
@alexggordon Thank you very much for the quick action.
sample:
The property
dates
is an array of object shapes like{ from: 36000, to: 42000 }
. I want to serializedates
, but I don't like to abstract the date object into a class, it's tiresome and not necessary ...Can we remove the required argument for
object()
, leave it empty that means forJSON.stringify
it.I can do this myself in my project, but I think this is a common case and it make sense, besides, I don't have to be compelled to dream up a new api name for this ...
What do you think about this ? @alexggordon