From 9470e1856630eb560a7f2cb65c4015fba3e3f0b8 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sun, 23 Feb 2014 10:21:30 -0800 Subject: [PATCH] Use .filter(). .filter() is awesome. --- common/content/modes.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/common/content/modes.js b/common/content/modes.js index 7aae6ddc..9ff71eb5 100644 --- a/common/content/modes.js +++ b/common/content/modes.js @@ -21,13 +21,7 @@ var Modes = Module("modes", { this._recording = false; this._replaying = false; // playing a macro - this._modeStack = update([], { - pop: function pop() { - if (this.length <= 1) - throw Error("Trying to pop last element in mode stack"); - return pop.superapply(this, arguments); - } - }); + this._modeStack = Modes.ModeStack([]); this._modes = []; this._mainModes = []; @@ -275,9 +269,8 @@ var Modes = Module("modes", { if (covert && this.topOfStack.main != mode) { util.assert(mode != this.NORMAL); - let i = this._modeStack.findIndex(m => m.main == mode); - if (i >= 0) - this._modeStack.splice(i); + this._modeStack = Modes.ModeStack( + this._modeStack.filter(m => m.main != mode)); } else if (this.stack.some(m => m.main == mode)) { this.pop(mode); @@ -489,6 +482,14 @@ var Modes = Module("modes", { }, { _id: 0 }), + ModeStack: function ModeStack(array) + update(array, { + pop: function pop() { + if (this.length <= 1) + throw Error("Trying to pop last element in mode stack"); + return pop.superapply(this, arguments); + } + }), StackElement: (function () { const StackElement = Struct("main", "extended", "params", "saved"); StackElement.className = "Modes.StackElement";