I have a page that displays a list of data.
The data model is built with SuperMap.
After save synchronized with socket for events.
I get the list with a method in the ViewModel.
This method allows me to filter the data.
Stage: (Work with 2 browser)
- Browser 1: show list - ok
- Browser 2: show list - ok
- Browser 1: change and save data - ok
- browser 2: LOSE modified record
This does not happen if the stache directly use the model exported.
This is my code
---prestador.js ----
import can from 'can';
import superMap from 'can-connect/can/super-map/';
import tag from 'can-connect/can/tag/';
import 'can/map/define/define';
import moment from "moment";
import io from 'steal-socket.io';
export const Prestador = can.Map.extend({ define: {} });
Prestador.List = can.List.extend({ Map: Prestador }, {});
export const prestadorConnection = superMap({
url: '/api/v1/prestadores',
idProp: 'CODIGOPRESTADOR',
Map: Prestador,
List: Prestador.List
});
const socket = io();
socket.on('prestadores-created', prestador => {prestadorConnection.createInstance(prestador)});
socket.on('prestadores-updated', prestador => {prestadorConnection.updateInstance(prestador)});
socket.on('prestadores-removed', prestador => {prestadorConnection.destroyInstance(prestador)});
tag('prestador-model', prestadorConnection);
export default Prestador;
----- list.js ----
...
import Prestador from 'app/models/prestador'
...
export var ViewModel = Map.extend({
define: {
...
prestadores: {
get() {
let params = {
$limit: this.attr('paginate.limit'),
$skip: this.attr('paginate.offset')
};
return Prestador.getList(params);
}
}
...
------list.stache -------------
...
{{#if prestadores.isPending}}
Loading
{{/if}}
{{#if prestadores.isResolved}}
{{#each prestadores.value}}
<div class="list-group-item">
{{name}} - {{lastname}}
</div>
{{/each}}
{{/if}}
Any help is very useful.