-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextensions.caching.js
26 lines (26 loc) · 1.1 KB
/
extensions.caching.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Object.defineProperty(Room.prototype, 'sources', {
get: function() {
// If we dont have the value stored locally
if (!this._sources) {
// If we dont have the value stored in memory
if (!this.memory.sourceIds) {
// Find the sources and store their id's in memory,
// NOT the full objects
this.memory.sourceIds = this.find(FIND_SOURCES)
.map(source => source.id);
}
// Get the source objects from the id's in memory and store them locally
this._sources = this.memory.sourceIds.map(id => Game.getObjectById(id));
}
// return the locally stored value
return this._sources;
},
set: function(newValue) {
// when storing in memory you will want to change the setter
// to set the memory value as well as the local value
this.memory.sources = newValue.map(source => source.id);
this._sources = newValue;
},
enumerable: false,
configurable: true
});