1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-09 13:14:13 +01:00

Make 'doc' available to group initializer.

This commit is contained in:
Kris Maglione
2011-08-08 12:19:01 -04:00
parent e23c96580c
commit 6debfa4132
3 changed files with 21 additions and 8 deletions

View File

@@ -119,9 +119,12 @@ var Map = Class("Map", {
.map(function ([i, prop]) [prop, this[i]], arguments)
.toObject();
args = update({ context: contexts.context },
this.hive.argsExtra(args),
args);
let orig = args;
args = update({
context: contexts.context,
doc: this.hive.group.lastDocument
}, args);
update(args, this.hive.argsExtra(args), orig);
let self = this;
function repeat() self.action(args)

View File

@@ -611,12 +611,13 @@ function call(fn) {
*/
function memoize(obj, key, getter) {
if (arguments.length == 1) {
let res = Object.create(obj);
for each (let prop in Object.getOwnPropertyNames(obj)) {
let get = __lookupGetter__.call(obj, prop);
if (get)
memoize(obj, prop, get);
memoize(res, prop, get);
}
return obj;
return res;
}
try {

View File

@@ -25,6 +25,9 @@ var Group = Class("Group", {
this.hives = [];
},
set lastDocument(val) { this._lastDocument = val && Cu.getWeakReference(val); },
get lastDocument() this._lastDocument && this._lastDocument.get(),
modifiable: true,
cleanup: function cleanup() {
@@ -271,7 +274,7 @@ var Contexts = Module("contexts", {
return frame;
},
groups: Class.memoize(function () this.matchingGroups(this.modules.buffer.uri)),
groups: Class.memoize(function () this.matchingGroups()),
allGroups: Class.memoize(function () Object.create(this.groupsProto, {
groups: { value: this.initializedGroups() }
@@ -283,8 +286,14 @@ var Contexts = Module("contexts", {
activeGroups: function (uri, doc) {
if (!uri)
({ uri, doc }) = this.modules.buffer;
return this.initializedGroups().filter(function (g) uri && g.filter(uri, doc));
var { uri, doc } = this.modules.buffer;
return this.initializedGroups().filter(function (g) {
let res = uri && g.filter(uri, doc);
if (doc)
g.lastDocument = res && doc;
return res;
});
},
flush: function flush() {