Skip to content
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

Using websockets to insert new records #149

Closed
daniel-de-wit opened this issue Apr 11, 2016 · 1 comment
Closed

Using websockets to insert new records #149

daniel-de-wit opened this issue Apr 11, 2016 · 1 comment

Comments

@daniel-de-wit
Copy link

I receive JSONAPI payload from a websocket which I normalise and insert into the store, like so:

Route ( with InfinityRoute mixin ):

createChatMessage(JSONApiPayload) {
  const store = this.get('store');
  const record =  store.push(store.normalize('chat-message', JSONApiPayload));

  // Update the infinityModel with the new record..
}

How should I insert this new record into the infinityModel ( properly )?

For now I extended the ember-infinity mixin with 2 public methods:

  pushRecord(record) {
    const infinityModel = this._infinityModel();

    infinityModel.pushObject(record._internalModel);
  },

  pushRecords(records) {
    records.forEach(record => {
      this.pushRecord(record);
    });
  }

Which I found in the open PR: #107

Then in my route I added the call to pushRecord like so:

createChatMessage(JSONApiPayload) {
  const store = this.get('store');
  const record = store.push(store.normalize('chat-message', JSONApiPayload));

  this.pushRecord(record);
}

My quick solution works, but there must be a better way? Any help on this would be greatly appreciated.

@hhff
Copy link
Collaborator

hhff commented Apr 11, 2016

HI @daniel-de-wit - yeah I agree - this isn't ideal.

We currently do this:
return infinityModel.pushObjects(newObjects.get('content'));

Which I don't love.

Currently all the methods that Ember Infinity use to populate the infinityModel are private - that's mostly by design, but we for sure need a more "supported" way for users to update their data.

This is partly related to #151 - we need a method of "creating" a new array from a supplied bit of data, and the current set. Would love to know your thoughts here!

@hhff hhff closed this as completed May 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants