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
Have conventional way of preloading data into the store #705
Comments
Any progress on this one? My old (hackish) way of bootstrapping data no longer works with b1, so before I hack together a new way a conventional solution would be nice... |
@nragaz there is currently an other issue about normalizing during push: #1199 (comment) |
@tomdale if @bradleypriest's code in #1199 (below) was made into a tested PR (in javascript no less!) would you accept? App.Store = DS.Store.extend
pushData: (prop, data) ->
type = @modelFor(prop)
serializer = @serializerFor(type)
if Ember.typeOf(data) is "array"
data = data.map (object) -> serializer.normalize(type, prop, object)
@pushMany(type, data)
else
data = serializer.normalize(type, prop, data)
@push(type, data) |
Also, I don't know if this is intentional or not, but pushing into the store does not push the object into hasMany arrays. Is this expected behaviour? Should adding a new object to the store also push into a hasMany array? Anyone have any info on this? |
@alexspeller - This works fine for me running on latest ember-data. Check the TRANSITION.md about changes made to relations and response serialisation. |
@Zeeraw are you talking about hasMany array being a live array? I've read the transition docs very carefully and it is still not working. |
@alexspeller I was referring to el = 'body'
key = 'session'
payload = JSON.parse($(el).attr(key))
$(el).attr(key,null)
record_id = payload[key].id
store = container.lookup('store:main')
factory = store.modelFor(key)
adapter = store.adapterForType(key)
store.push(key, adapter.get('serializer').extractSingle(store, factory, payload)) |
There is now a method to push data into the store, which is awesome 4bf1b7a. Example In our case this static data is never persisted, but there are certainly use cases where data is preloaded but still need to be modified. Possible solutions
|
@sandstrom doesn't store have .all() which has the behaviour you want, I.e. return all records currently in the store without making a request and updating the array returned if more records arrive? Or is that gone now? |
@alexspeller It's still around, thanks!! |
I'm closing this due to #1309. It might be nice to have <script type="text/x-bootstrap-payload"> that "just works". Anyone want to grab it? |
Often, developers want to include a batch of data with the initial HTML request for the application, so that an additional "data-only" XHR isn't required to boot the app.
We should provide a convention for doing this.
The text was updated successfully, but these errors were encountered: