所以我刚刚读到Angular2的Build.gradle
,它检查对象是否相等,以确定是否应该更新DOM。
现在假设我有一个不可变的android {
compileSdkVersion 22
buildToolsVersion '23.0.2'
defaultConfig {
applicationId 'info.guardianproject.otr.app.im'
minSdkVersion 9
targetSdkVersion 21
.....
.....
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.0.0'
compile project(':AndroidEmojiInputLibrary')
compile project(':AndroidPinning')
compile project(':CacheWordLib')
compile project(':MemorizingActivity')
compile project(':SlidingMenuLibrary')
compile project(':TibetanTextLibrary')
compile project(':ViewPagerIndicatorLibrary')
compile 'com.google.firebase:firebase-messaging:9.0.0'
}
apply plugin: 'com.google.gms.google-services'
对象,如果你更改了ChangeDetector
属性,引用就会改变。
Person
听起来很酷。但是当我尝试在这样的情况下使用它时,它给了我噩梦:
name
早些时候,我可以做class Person {
private _name: string;
constructor(name: string) { this._name = name; }
get name(): string { return this._name; }
setName(name: string): Person {
if (name === this.name) return this;
return new Person(name);
}
}
之类的事情。
但现在我需要编写以下代码:
class System {
students: {me: Person, parent: Person}[];
parents: Person[];
}
为了确保满足以下约束条件:
this.parents[0].name = 'NewName'
引用也应更改。changeParentName(index: number, name: string) {
let parent = this.parents[index];
let newParent = parent.setName(name);
if (parent === newParent) return;
this.parents.splice(index, 1, newParent);
this._parents = _.clone(this.parents);
this._students = _.map(this.students, student => {
if (student.parent !== parent) return student;
return {
me: student.me,
parent: newParent
}
});
}
引用也会更改。使用immutables真的很复杂吗?或者我错过了一些非常明显的东西?