Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to manually set an object state to clean (saved) using ember-data
    primarykey
    data
    text
    <h2>Explanation:</h2> <p>I'm using ember-data for a project of mine and I have a question that revolves around the possibility of dirtying an object and then setting its state to clean again on purpose - without commiting the changes. The scenario is this:</p> <p>Say I've fetched an object via <code>banana = App.Fruit.find('banana');</code> and it has a description of "Yellow fruit!". Using XHR long-polling (or WebSockets), I may receive an updated version of the object because of another user having changed the description to "A tasty yellow fruit!" at any given point in time <em>after</em> I fetched the original object.</p> <p>Then, what I would like to do is to update the object to reflect the newly received data. For this, I've tried different approaches:</p> <ul> <li><p>I've tried calling <code>App.Store.load(App.Fruit, new_data);</code>. First of all, this approach doesn't work and secondly, this is not really what I want. I could've made uncommitted changes to the object myself and in this case, it would be undesirable to just discard those (assuming the <code>load()</code> call would overwrite them).</p></li> <li><p>I've tried looping through the new data, calling <code>.set()</code> - like so: <code>banana.set('description', new_data.description);</code> - in order to update the object properties with the new data (where applicable = not dirty). This works but it leaves the object in a dirtied state.</p></li> </ul> <p>In order to make the object clean/updated again - and <strong>not</strong> have the adapter commit the changes! - I've taken a look at the states the object travels through. These are (at least):</p> <ul> <li>Step 1: Initially, the object is in the <code>rootState.loaded.saved</code> state.</li> <li>Step 2: Calling <code>.set()</code> on a property pushes it to the <code>rootState.loaded.updated.uncommitted</code> state.</li> <li>Step 3: Calling <code>App.store.commit();</code> returns the object to the <code>rootState.loaded.saved</code> state.</li> </ul> <p>Therefore, I've tried to manually set the object state to <code>saved</code> after step 2 like so: <code>banana.get('stateManager').goToState('saved');</code>.</p> <p>However, this doesn't work. The next time the store commits for any other reason, this maneuver produces an <em>inFlightDirtyReasons is undefined</em> error.</p> <h2>Question:</h2> <p>My question is: how can I manually change the state of a dirtied object back to clean (saved) again?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload