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

The service_name.store.records is not updating just replace the last item #27

Open
hugomosh opened this issue Aug 15, 2017 · 7 comments
Labels

Comments

@hugomosh
Copy link

hugomosh commented Aug 15, 2017

Steps to reproduce

I have one project ReactNative and Feathers with a service lets say service_logs

Behavior

  1. I create a new service_log: SERVICES_DEVICE_LOGS_CREATE_PENDING
  2. Service create the device: SERVICES_DEVICE_LOGS_CREATE_FULFILLED
  3. But in the service_logs.store.records (SERVICES_DEVICE_LOGS_STORE) I get the last item "replace" for the new one. See the image:

captura de pantalla 2017-08-15 a la s 15 39 15

It should keep the full list, not replacing the last item. You see 301,299,298,... When it should be 301,300,299,298,...

I do something like this to connect RealTime

if (s == 'device_logs') {
    options = {
       uuid: true ,
      sort: Realtime.multiSort({created_at: -1})
    }
  }
  const serviceRT = new Realtime(serviceN, options);

  serviceRT.on('events', (records, last) => {
    store.dispatch(services[s].store({connected: serviceRT.connected, last, records}));
  });
  RealTimesV[s] = serviceRT;

And then I do an action to connect to the service.

I am not sure if this weird behavior is on the server side or the real time.

Thanks.

@eddyystop
Copy link
Collaborator

The store method just copies the param to the Redux store.

This repo, like other Feathers repos, does not deep clone objects because of the performance cost. Passing a cloned object will avoid side effects and perhaps resolve this.

@eddyystop
Copy link
Collaborator

Copy of PMs on this issue:

@eddyystop
Copy link
Collaborator

I found your code

if (s == 'device_logs') {
  options = {
    uuid: true ,
    sort: Realtime.multiSort({created_at: -1})
  }
}
const serviceRT = new Realtime(serviceN, options);

serviceRT.on('events', (records, last) => {
  store.dispatch(services[s].store({connected: serviceRT.connected, last, records}));
 });

@eddyystop
Copy link
Collaborator

I assume you a serviceRT.connect() at some point.

[11:47]
Please add an app.service(name).on('created', data => console.log(data)) as well as updated, patched, removed someplace. Please log records & last inside serviceRT.on('events', (records, last) => {. This will allow us to see the mutations occurring and the state of the store.

But first check that each of your records has a unique uuid [edit: since you use the uuid: true option]. A uuid is just like id || _id. Duplicates are updates not creates. There's how the replicator generates uuid's https://github.com/feathersjs/feathers-offline-realtime/blob/master/src/commons/utils/cryptographic.js

[6:56]
Just noting your issue url here for myself #27

[6:58]
And if you don't have a uuid field you need a unique id or _id field.

@hugomosh
Copy link
Author

hugomosh commented Aug 27, 2017 via email

@eddyystop
Copy link
Collaborator

Just to be clear, you added the name of the uuid column as an option? Perhaps you could submit a PR?

@bitflower
Copy link

bitflower commented Mar 8, 2018

@hugomosh Did you actually dispatch the STORE action actively yourself through redux-saga or feathers-offline-realtime ? Or is feathers-redux supposed to dispatch the STORE action automatically after say SERVICE_FIND_FULFILLED?

@eddyystop you may answer this is well of course 👍

EDIT: My fault. Saw it in your code sample.....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants