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 )=> {
return resolve( this.mockStores.toArray() );
} );
}
} export default ( ngModule ) => {
ngModule.service( 'StoreService', StoreService );
}

Try to only keep 'serivce' to deal with Immutable data, controller should have no knowledge about whether the data in mutable type or immutable type.

So when return the data to the controller, we sue '.toArray()' method to convert the Immutable data structure to normal Javascript array method.

------------------------------

The reason here we use both 'const' and Immutable is because:

 const _person = {
name: "Zhentian"
}; class StoreService {
constructor( ) {
this.person = _person; this.person.name = "John";
console.log(_person.name); // --> John } } export default ( ngModule ) => {
ngModule.service( 'StoreService', StoreService );
}

In the contructor we define:  '_person' assign to 'this.person', even _person is const type, but when we try to modiy the data thougth this.person object, we found actually we are able to do that.

So the const is not safe when deal with object!

So we still need Immutable to help us to keep data immutable.

最新文章

  1. iOS_直播类app_HTTP Live Streaming
  2. [Linux][PHP]安装swoole扩展
  3. Hibernate 继承映射
  4. Yii2使用教程
  5. Also unsere eigene Christian Louboutin Webshop bietet die überragende Christian Louboutin Schuhe uk schiebt zusammen mit kostengünstigen Wert
  6. 全面理解Context
  7. (转) Deep Reinforcement Learning: Pong from Pixels
  8. C++ this指针详解
  9. Uber新功能:隐藏司机乘客们的手机号码
  10. 某外企mono for android试题
  11. 【USACO 1.5.4】跳棋的挑战
  12. 201521123013 《Java程序设计》第4周学习总结
  13. 小程序坑之 swiper组件
  14. (转载)关于usr/bin/ld: cannot find -lxxx问题总结
  15. JMeter-Java压力测试工具-01
  16. 使用STM32的USART的同步模式Synchronous调戏SPI【usart模拟spi理论】
  17. Unity3D编辑器之不实例化Prefab获取删除更新组件
  18. python3 from Tkinter import * 和import Tkinter as tk两个区别import Tkinter
  19. Python学习笔记(四十五)网络编程(1)TCP编程
  20. HackerRank - journey-to-the-moon 【并查集】

热门文章

  1. FileZilla简单介绍及运用
  2. 解决linux不能使用chmod更改权限的问题
  3. CSS background 属性 总结
  4. ajax例子
  5. JavaScript可否多线程? 深入理解JavaScript定时机制(转载)
  6. Python之路第二天,基础(2)-基本数据类型
  7. python3.4入门——核心数据类型
  8. [bzoj1002][FJOI2007 轮状病毒] (生成树计数+递推+高精度)
  9. Codeforces 474D Flowers
  10. hex、bin、elf、axf文件区别