Attempt to fix cache crash

This commit is contained in:
abalabahaha
2016-03-12 23:40:07 -08:00
parent 930f276828
commit 42bedbeee4
2 changed files with 26 additions and 36 deletions

View File

@@ -115,20 +115,18 @@ var Cache = (function (_Array) {
}; };
Cache.prototype.update = function update(old, data) { Cache.prototype.update = function update(old, data) {
var item = this.get(this[discrimS], old[this[discrimS]]); for (var i in this) {
if (this[i][this[discrimS]] === old[this[discrimS]]) {
if (item) { for (var key in data) {
var index = this.indexOf(item); if (data.hasOwnProperty(key)) {
for (var dataIndex in data) { this[i][key] = data[key];
if (data.hasOwnProperty(dataIndex)) { }
this[index][dataIndex] = data[dataIndex];
} }
this[discrimCacheS][data[this[discrimS]]] = this[i];
return this[i];
} }
this[discrimCacheS][data[this[discrimS]]] = this[index];
return this[index];
} else {
return false;
} }
return false;
}; };
Cache.prototype.random = function random() { Cache.prototype.random = function random() {
@@ -137,13 +135,10 @@ var Cache = (function (_Array) {
Cache.prototype.remove = function remove(data) { Cache.prototype.remove = function remove(data) {
delete this[discrimCacheS][data[this[discrimS]]]; delete this[discrimCacheS][data[this[discrimS]]];
var index = this.indexOf(data); for (var i in this) {
if (~index) { if (this[i][this[discrimS]] === old[this[discrimS]]) {
this.splice(index, 1); this.splice(i, 1);
} else { return this[i];
var item = this.get(this[discrimS], data[this[discrimS]]);
if (item) {
this.splice(this.indexOf(item), 1);
} }
} }
return false; return false;

View File

@@ -79,20 +79,18 @@ export default class Cache extends Array {
} }
update(old, data) { update(old, data) {
var item = this.get(this[discrimS], old[this[discrimS]]); for(var i in this) {
if(this[i][this[discrimS]] === old[this[discrimS]]) {
if (item) { for (var key in data) {
var index = this.indexOf(item); if (data.hasOwnProperty(key)) {
for (var dataIndex in data) { this[i][key] = data[key];
if (data.hasOwnProperty(dataIndex)) { }
this[index][dataIndex] = data[dataIndex];
} }
this[discrimCacheS][data[this[discrimS]]] = this[i];
return this[i];
} }
this[discrimCacheS][data[this[discrimS]]] = this[index];
return this[index];
} else {
return false;
} }
return false;
} }
random() { random() {
@@ -101,13 +99,10 @@ export default class Cache extends Array {
remove(data) { remove(data) {
delete this[discrimCacheS][data[this[discrimS]]]; delete this[discrimCacheS][data[this[discrimS]]];
var index = this.indexOf(data); for(var i in this) {
if (~index) { if(this[i][this[discrimS]] === old[this[discrimS]]) {
this.splice(index, 1); this.splice(i, 1);
} else { return this[i];
var item = this.get(this[discrimS], data[this[discrimS]]);
if (item) {
this.splice(this.indexOf(item), 1);
} }
} }
return false; return false;