Immutable.js 记录上的方法是否复制?
Do methods on Immutable.js Records replicate?
我的应用加载了大约 30-50 个 Immutable.js Record
实例。我想写一个 getter
在返回数据之前对数据应用一些操作。
这样有效率吗?或者我最终会在内存中保留我编写的任何方法的 30-50 个副本?
预计到达时间:
这是我当前的模式:
export const EntityRecord = Immutable.Record({
// key/values
})
class Entity extends EntityRecord {
getProp() {
return this.get('property')
}
}
这取决于实施。你可以简单地写一个实用方法
export function myRecordGetter(myRecord) {
... do your work here ....
return thingYouComputed;
}
然后只需导入并调用它。如果您打算 "extend" 记录的功能,这取决于您如何做。
我的应用加载了大约 30-50 个 Immutable.js Record
实例。我想写一个 getter
在返回数据之前对数据应用一些操作。
这样有效率吗?或者我最终会在内存中保留我编写的任何方法的 30-50 个副本?
预计到达时间:
这是我当前的模式:
export const EntityRecord = Immutable.Record({
// key/values
})
class Entity extends EntityRecord {
getProp() {
return this.get('property')
}
}
这取决于实施。你可以简单地写一个实用方法
export function myRecordGetter(myRecord) {
... do your work here ....
return thingYouComputed;
}
然后只需导入并调用它。如果您打算 "extend" 记录的功能,这取决于您如何做。