-
-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ember Data Record Data RFC #293
Conversation
I feel like the name "ModelData" provides little meaning. I agree that a different name is necessary. |
text/0000-model-data.md
Outdated
5) Certain apps and models have a large amount of read only data, which is currently very performance heavy | ||
to implement in ED. They could use a read only fast model data addon, which would enable a large perf win. | ||
|
||
6) Experimenting with schemaless approaches is currently very hard in ED, because internal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would love to hear how this would affect https://github.com/hjdivad/ember-m3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the effects of this API codification is to enable addons like ember-m3, model-fragments &c. to avoid private API, and be easier to maintain between ember-data upgrades.
AdapterWillCommit and adapterDidCommit should be renamed to willCommit and didCommit to avoid leaking the store architecture into MD. that way a different way of getting data eg GraphQL that doesn’t use adapters can be implemented in future. |
A few thoughts/questions
Overall I think the RFC looks really good. I'm excited to make it easier to create addons for ember-data. |
While experimenting with an ember-data addon using model-data, we discovered a few limitations around lifecycle information. We believe three additional hooks are needed. The names I'm proposing below are likely in-need-of-improvement.
|
This should be handleable via
Having thought about this a bit I strongly suspect the right approach will be to
This way abstractions specific to a particular |
@hjdivad that’s only true if server doesn’t change id. Creation is two phase -
|
Please let’s remove adapter from method names to allow different comms channels in future (eg websocket push) |
I fail to see the point you are making here, the
I suspect David mistyped On that note, |
Interesting! A few thoughts:
|
@mixonic you provide a |
When I wrote the comment the RFC still had it named |
@igorT you’re suggesting the app developer is responsible for combining different addons? That doesn’t sound very easy. Eg you might have an add on that implements local caching and another that implements websocket updates. It’s important which order the addons are _supered in. Perhaps something along the lines of a pipeline could be imagined and the addon Dev can insert the addon into the pipeline in the right place. Or a separate addon could create a common pipeline along the lines of ember-deploy |
I'd like to renew my objection to the name "ModelData". It provides little meaning. If nothing else, let's call it "InternalModel", that is what it is replacing and furthermore lets casual users know they probably shouldn't touch it. :) IMO naming is important. |
I'd like to give a perspective from someone who is using ember-data for undo/redo tracking (by recording all changes to the model in the adapter, with code to reverse them). I got it to work, but I stumbled upon two issues:
|
I am curious if this RFC addresses an issue that comes up often in editing and creating new records. Currently if you want to edit or create a record you have one path. You can edit the model itself and save it. You can create the model and save it. You could use a buffered proxy on edit of course, but once you start the save, all the changed attributes need to be set on the model before the the model can be saved. You can create an ember object that sort of acts like a model ( you can set properties on it ) but once you want to create you have to create record in the store and save that. This means that saving / creating is always immediately impacting the state of the model/store and the UI. There is no way to cleanly make edits / creates that don't affect the model or store until after the model save is complete. What I envision is a way for Ember Data users to create changes in a Model or create a new Model that looks like a model and acts like a model but is not yet in the store. They could then change this fake proxy like Model, serialize it, send the data to the backend and then update the model ( apply the changes after save success or not apply them on failure ). So, what I am trying to say is that I would like ember data users to be able to have a Would this RFC help in that regard? Or would there be other work to be done? |
@danielspaniel it does not directly but it does open the door for adding to do so |
@danielspaniel What you'd actually want for this is operational transforms instead of straight record objects, because you want to track changes and apply them to the model later. Incidentally, this is the same as I need for undo/redo support. I'm afraid that this is something that doesn't really fit into ember's concepts, so this might not work for ember-data. |
Heartily disagree. Ember is just Javascript and Orbit handles this concept quite nicely. This RFC will enable orbit+Ember-Data to become a potential reality. But yes, in Ember Data today OT is not something we do or make easy for others to do. We've been discussing for some time what the right boundary between adapter and store would be in the future, a future this RFC helps us to explore. Major themes have included removing some of the restrictions on state keeping and request management that the store unnaturally imposes today. I'm optimistic that this is a huge step forward to enabling Ember Data to evolve as a project as needed. |
I really have fundamental problems with how ED has evolved over recent years. The multiple refactors that ED has gone through, IMHO, have made it less extensible and maintainable. I am generally in favor of this RFC but have some concerns I'd like to put out there. In its current state, ED "assumes" too much:
I'd really, really, really like to see all internal use of the JSON API spec eleminated and 'just' deserialize an incoming From a highlevel, I believe: The The The The The Ideally, I'd like to be able to implement three interfaces to support my particular backend needs:
|
Thanks for all the great work here, everyone. Really excited to see some major ED improvements on the way. And I realize how difficult it is to evolve without heavily breaking backwards compatibility, so 👍 on all of your work. I would like to share my biggest pain point with ED and see if this will have potential for resolution. As Ember has evolved over the years, its philosophy has shifted from two-way bindings everywhere to a more unidirectional data flow ("data down actions up"). This made Ember application code much easier to reason about and reduced the number of unintended side-effects from changes to bound properties. Ember Data, however, still has a two-way binding feel that causes some fairly severe long-lived state problems. Some examples:
Out of the box, this can be very error prone. It feels like the two-way binding problems because a model can change by either the adapter or locally, resulting in many side-effects. There are several Ember addons that try to address this by buffering the changes in a separate object, but they all have some limitations and problems, such as relationships not being rolled back properly, computed properties not using the adjusted data, etc. They do their best to work around this problem, because it cannot otherwise be solved without some fundamental changes to Ember Data. When you examine a server-side database + ORM, this problem does not exist. Consider this Ruby on Rails pseudo example: def update
post = Post.find(params[:id])
post.title = params[:title]
if post.save
render post
else
render post.errors, status: 422
end
end Here, ActiveRecord requests the record from the database. The database will always only contain known, valid records. The That said, my preferred data flow would be something like this:
I believe the more we can adopt this strategy, the more natural Ember Data will feel and the less error prone it will be. I understand that this RFC does not address all of this... but do the proposed changes at least make this feasible, and if so, can you briefly explain how? |
@christophersansone .. I don't mean to sound like you mom, but I asked the same question already, and it was already answered. If you read the post about 3 days ago that has this in it: So, what I am trying to say is that I would like ember data users to be able to have a |
@danielspaniel Thanks Mom! 😉 Okay yeah sorry, some different semantics but generally the same question. It seems to me to mostly boil down to being able to create an actual instance of a model that is detached from the store. Setting its data to copy an existing record seems trivial at that point. Then we can have our own patterns for sending data through the adapter and pushing the changes back to the store. Could even be an addon as the pattern becomes refined. But it's an impossibility now due to model instances being so tightly coupled to the store. |
@christophersansone @danielspaniel
Then we can look at whether changes in uncommitted transactions are visible to the rest of the system - this would be a nice config on the store so you can have the best of both worlds. Also means you can Save a transaction back to the server, while a second transaction is in progress, so it's easy to command sparse PATCHes. |
Hi all, I agree that Ember Data needs something like a transactional model. However, addons can and do address this. See ember-buffered-proxy, ember-changeset, and others. I think all of this is out of scope for this RFC. When the addon community comes up with a solution to this problem that the community commonly uses and agrees is best and actually workable, I think we can RFC that. I think we should continue to discuss this elsewhere, perhaps open a separate issue on this repo. |
@christophersansone , @BryanCrotaz .. we are 100% on the same wavelength, and when the time comes and ember data is updated with this abstraction, I am going to jump on this for an addon, and I'd be happy if you would join me. Just bring some apple juice , and a few slices of lime and we can get on to making this a reality. |
@Gaurav0 |
In order to achieve all these lovely ideas, ModelData needs to have a pretty maximal footprint within the Store. |
@BryanCrotaz 👍 for Delphi back in the day! Yes optimally a larger long-term solution would cover more than a single record. My current opinion is that it can be important but less critical, particularly because JSON:API does not have native support for batch updates (yet). @Gaurav0 Wholeheardly disagree, as stated in my initial post. These current addons are workarounds that address some but not all of the problems, and they introduce some of their own problems: relationships may not work properly, computed properties may not behave as expected, etc. A new Ember developer will notice things don't work as expected, run into problems, attempt to resolve on their own, search for addons, and run into different problems. I believe this issue is at very core of ED. Much like when the Ember core team changed direction from two-way bindings to Data Down Actions Up... they didn't just say "hey, if you think this is a problem, go find an addon to fix it". They saw a fundamental problem with Ember, they discovered a better approach, and they addressed it at the core. I don't necessarily expect the ED team to necessarily rewire everything, but at least hopefully offer the proper abstractions so that developers and addon authors can do so. We've all been there, right? "Hmm, what is this empty record doing in my list? Oh, I created it but didn't save it, and it's showing up in the list? How weird. I need to find a way to fix that." |
@christophersansone Believe me, I know current addons aren't enough. Recently I wrote a promise proxy version of ember-buffered-array-proxy for async hasMany array-like objects. I am trying to get permission to open source it. But these one off solutions aren't enough for dealing with all relationships. What I'm saying is that these problems can't be solved just by the Model Data RFC and should be discussed in a separate issue, so as to allow people to discuss and comment on this RFC's issues here without searching through a discussion of a larger problem. |
@Gaurav0 Thanks for the clarification. Agreed that this discussion is starting to take a life of its own.
I respectfully disagree. My understanding of this RFC is to refactor the internal models and expose some public APIs so that the model classes are less brittle and can be more adaptable. If this refactoring provides the ability for a model instance to exist outside of the store, then this is the first step. If not, I would ask that they consider some ability to solve for this. This seems to be very much within the context of this RFC. I wrote a lot more about the problem and my ideal solution, in an effort to fully explain the need. |
Further to @christophersansone maybe we need a list of the types of addon that we're looking to support with this new public API. I'll make a start:
We then need to make sure that the properties and actions these addons would need to intercept / override are present in the public API |
Hello, mundo 👋 Finally got around to have a look at this RFC. I'm happy that work is being done to try to bring order to ED's dirty laundry :P I have a couple of comments, hopefully they weren't addressed by/in earlier comments:
|
@emberjs/ember-data-contributors - Where are we at with this? Anything needed to do before landing? Any outstanding concerns? |
In order to merge this, we still need to update the text to reflect the name change from |
Ping @igorT 😄 |
Rendered