feathers-redux
feathers-redux copied to clipboard
The service_name.store.records is not updating just replace the last item
Steps to reproduce
I have one project ReactNative and Feathers with a service lets say service_logs
Behavior
- I create a new service_log: SERVICES_DEVICE_LOGS_CREATE_PENDING
- Service create the device: SERVICES_DEVICE_LOGS_CREATE_FULFILLED
- But in the service_logs.store.records (SERVICES_DEVICE_LOGS_STORE) I get the last item "replace" for the new one. See the image:
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.
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.
Copy of PMs on this issue:
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}));
});
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.
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 .
Just to be clear, you added the name of the uuid
column as an option? Perhaps you could submit a PR?
@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.....