Const STORES = immutable.list([{name:' Store42 ', Position: {Latitude:61.45, Longitude:23.11,}, Address:' Whatever '}, {name:' Store2 ', Position: {Latitude:61.48, Longitude:23.87}, Address:' Whatever '}, {name:' Store3 ', Position: {Latitude:61.41, Longitude:23.76}, Address:' Whatever '}, {name:' Store4 ', Position: {Latitude:61.42, Longitude:23.40}, Address:' Whatever '}]); class Storeservice {constructor ($q) { This. $q =$q; This. Mockstores =stores; } getstores (position) {return This. $q ((Resolve) = { returnResolve This. Mockstores. ToArray () ); } ); }}exportdefault(ngmodule) ={Ngmodule.service (' Storeservice ', Storeservice);}
Try to only keep ' serivce ' to deal with immutable data, controller should has no knowledge about whether the data in Muta BLE type or immutable type.
When you return the data to the controller, we Sue '. ToArray () ' method to convert the immutable data structure to normal Ja Vascript Array method.
------------------------------
The reason here we use both ' const ' and immutable are because:
Const _person = { "Zhentian" };class Storeservice { Constructor ( ) { this . person = _person; this. Person.name = "John"; // - John Default (Ngmodule) = { ' storeservice ', Storeservice);}
In the contructor we define: ' _person ' assign to ' This.person ', even _person are const type, but if we try to modiy the Data Thougth This.person object, we found actually we are able to do.
So the const isn't safe when deal with object!
So we still need immutable to help us to keep data immutable.
[Immutable + AngularJS] Use immutable. List () for Angular array