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.

[Immutable + AngularJS] Use Immutable .List() for Angular array的更多相关文章

  1. [Immutable.js] Transforming Immutable Data with Reduce

    Immutable.js iterables offer the reduce() method, a powerful and often misunderstood functional oper ...

  2. Immutable Collections(3)Immutable List实现原理(中)变化中的不变

    Immutable  Collections(3)Immutable List实现原理(中)变化中的不变 文/玄魂 前言 在上一篇文章(Immutable Collections(2)Immutabl ...

  3. [AngularJS] Isolate State Mutations in Angular Components

    Managing state is one of the hardest things to do in any application. Angular 2 tackles this problem ...

  4. [Immutable.js] Converting Immutable.js Structures to Javascript and other Immutable Types

    Immutable.js provides several conversion methods to migrate one structure to another. Each Immutable ...

  5. AngularJS开发指南3:Angular主要组成部分以及如何协同工作

    AngularJS的主要组成部分是: 启动(startup) - 展示“hello world!” 执行期(runtime) - AngularJS 执行期概览 作用域(scope) - 视图和控制器 ...

  6. AngularJS进阶(三十四)Angular数据更新不及时问题探讨

    Angular数据更新不及时问题探讨 前言 在修复控制角标正确变化过程中,发觉前端代码组织层次出现了严重问题.传递和共享数据时自己使用的是rootScope,为此造成了全局变量空间的污染.根据< ...

  7. AngularJS入门讲解1:angular基本概念

    AngularJS应用程序主要有三个组成部分: 模板(Templates) 模板是您用HTML和CSS编写的文件,展现应用的视图. 您可给HTML添加新的元素.属性标记,作为AngularJS编译器的 ...

  8. AngularJS学习(二)——Angular应用的解析

    本节描述AngularJS应用程序的三个组成部分,并解释它们如何映射到模型-视图-控制器设计模式 模板(Template) 模板是您用HTML和CSS编写的文件,展现应用的视图.您可给HTML添加新的 ...

  9. [AngularJS] Adding custom methods to angular.module

    There are situations where you might want to add additional methods toangular.module. This is easy t ...

随机推荐

  1. 【POJ2114】Boatherds 树分而治之

    做广告: #include <stdio.h> int main() { puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog. ...

  2. Leetcode_num3_Same Tree

    题目: Given two binary trees, write a function to check if they are equal or not. Two binary trees are ...

  3. 安装软件配置VC++环境时常出现的问题--Error 1935.安装程序集

    装很多软件是都要配置VC++环境的,但由于系统注册表限制,很多时候软件安装过程中会报如下错误 安装 vc++2005 运行库 Error 1935.安装程序集 Microsoft.vc80.atl,t ...

  4. 《第一行代码》学习笔记2-Android开发特色

    1.四大组件:活动(Activity),服务(Service),广播接收器(Broadcast Receiver),内容提供器(Content Provider). Activity:应用中看得到的东 ...

  5. centos打开3306端口

    centos默认是关闭了3306端口的,外网通过3306端口不能访问数据库,这时需呀打开3306端口1.打开端口: /sbin/iptables -I INPUT -p tcp --dport 330 ...

  6. C#类型基础——学习笔记一

    1.C#中的类型一共分两类,一类是值类型,一类是引用类型.2.结构类型变量本身就相当于一个实例.3.调用结构上的方法前,需要对其所有的字段进行赋值.4.所有元素使用前都必须初始化.5.(结构类型)ne ...

  7. C#holle world

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. JVM的内存区域划分划分及作用

  9. C语言结构体的字节对齐

    Test Code: #include <iostream> #include <cstring> using namespace std; struct A{ int a; ...

  10. 解决Windows 7/win8 使用VMware虚拟机的NAT 不能上网

    最近在学习linux系统,在使用debian6更新源的时候,发现Nat模式上网就是配置不了.而内外网可以ping通.所以很苦恼.最后终于解决了. 以下操作在VMware10下进行 1.首先要设置一下 ...