feathers-redux icon indicating copy to clipboard operation
feathers-redux copied to clipboard

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

Open hugomosh opened this issue 7 years ago • 7 comments

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.

hugomosh avatar Aug 15 '17 20:08 hugomosh

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 avatar Aug 16 '17 00:08 eddyystop

Copy of PMs on this issue:

eddyystop avatar Aug 17 '17 14:08 eddyystop

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 avatar Aug 17 '17 14:08 eddyystop

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 https://github.com/feathersjs/feathers-redux/issues/27

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

eddyystop avatar Aug 17 '17 14:08 eddyystop

Yes, indeed the error was plain simple, we used the table_name_id standard so we did't have the id field. And recently we changed to postgres instead of json DB so the uuid was not taking effect. We created a fork to add the name of the identifier column in the options of the RealTime configuration. And it has been working like a charm.

Thank you for all the patience and comments.

El jue., 17 de ago. de 2017 a la(s) 09:32, Eddyystop < [email protected]> escribió:

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 https://github.com/feathersjs/feathers-redux/issues/27

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

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/feathersjs/feathers-redux/issues/27#issuecomment-323085850, or mute the thread https://github.com/notifications/unsubscribe-auth/AA21ehmdaBQQJyg1r_r45jakkz6OeVwbks5sZEpngaJpZM4O4GTq .

hugomosh avatar Aug 27 '17 06:08 hugomosh

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

eddyystop avatar Aug 27 '17 22:08 eddyystop

@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.....

bitflower avatar Mar 08 '18 10:03 bitflower