# Lost data after save in other client

**URL:** <https://forums.bitovi.com/t/lost-data-after-save-in-other-client/449>\
**Category:** CanJS\
**Created:** [October 20, 2016, 5:11pm UTC](https://forums.bitovi.com/t/lost-data-after-save-in-other-client/449 "2016-10-20T17:11:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alejandro\_Parra](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@Alejandro\_Parra](https://forums.bitovi.com/u/Alejandro_Parra)\
**Post date:** [October 20, 2016, 5:11pm UTC](https://forums.bitovi.com/t/lost-data-after-save-in-other-client/449/1 "2016-10-20T17:11:26Z")

</div>

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)

1. Browser 1: show list - ok
2. Browser 2: show list - ok
3. Browser 1: change and save data - ok
4. 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.

---

<div class="post-metadata">

**Author:** ![justinbmeyer](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/justinbmeyer/32/179_2.png) [@justinbmeyer](https://forums.bitovi.com/u/justinbmeyer)\
**Post date:** [October 25, 2016, 3:11am UTC](https://forums.bitovi.com/t/lost-data-after-save-in-other-client/449/2 "2016-10-25T03:11:47Z")

</div>

What do you mean by:

> LOSE modified record

It disappears? My guess is that your set logic isn’t right. You need to make sure that that modified record would pass [algebra.has](http://canjs.github.io/canjs/doc/can-set.Algebra.prototype.has.html).

This means that if you loaded your data like:

```auto
Prestador.getList({foo: "bar"})

```

And your instance looks like `{id: 1, something: "value"}`.

You need to make sure

```auto
algebra.has({foo: "bar"}, {id: 1, something: "value"}) //-> true

```

Also, what do you mean by:

> This does not happen if the stache directly use the model exported.

---

<div class="post-metadata">

**Author:** ![Alejandro\_Parra](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@Alejandro\_Parra](https://forums.bitovi.com/u/Alejandro_Parra)\
**Post date:** [October 25, 2016, 12:46pm UTC](https://forums.bitovi.com/t/lost-data-after-save-in-other-client/449/3 "2016-10-25T12:46:18Z")

</div>

thanks for answer me.

Yes. when I work with two diferentes instances browser, the list that wasn’t modified, lost the data.  
fortunately, now it is working.  
My REST API is written with feathers-knex. For filter de data I use two params names $limit and $skip. This is the problem after update.  
_I don’t know why this happens._  
My solution was write the algebra function for Prestador.

```
    export const prestadorConnection = superMap({
    ...
      Map: Prestador,
      List: Prestador.List,
      algebra:new set.Algebra({
      	"$sort" : function(){ return true },
      	"$limit" : function(){ return true },
      	"$skip" : function(){ return true },
      	"$select" : function(){ return true }
    })
    });

tag('prestador-model', prestadorConnection);

export default Prestador;

```

What I mean by :

> This does not happen if the stache directly use the model exported.

This not happen when I use this way:

```
<prestador-model get-list="{}">
	{{#each ./value}}
		...
	{{/each}}
</prestador-model>

```

because there are unfiltered data.
