actions are a list, to reduce garbage
This commit is contained in:
parent
59b8a104c2
commit
cc4bcb341e
|
@ -121,7 +121,7 @@
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (p !== Empty.EMPTY) {
|
if (p !== EMPTY) {
|
||||||
texts.push('.');
|
texts.push('.');
|
||||||
texts.push(baselib.format.toDisplayedString(p, cache));
|
texts.push(baselib.format.toDisplayedString(p, cache));
|
||||||
}
|
}
|
||||||
|
@ -138,14 +138,14 @@
|
||||||
while (p instanceof Cons) {
|
while (p instanceof Cons) {
|
||||||
node.appendChild(baselib.format.toDomNode(p.first, cache));
|
node.appendChild(baselib.format.toDomNode(p.first, cache));
|
||||||
p = p.rest;
|
p = p.rest;
|
||||||
if (p !== Empty.EMPTY) {
|
if (p !== EMPTY) {
|
||||||
node.appendChild(document.createTextNode(" "));
|
node.appendChild(document.createTextNode(" "));
|
||||||
}
|
}
|
||||||
if (typeof (p) === 'object' && cache.containsKey(p)) {
|
if (typeof (p) === 'object' && cache.containsKey(p)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (p !== Empty.EMPTY) {
|
if (p !== EMPTY) {
|
||||||
node.appendChild(document.createTextNode("."));
|
node.appendChild(document.createTextNode("."));
|
||||||
node.appendChild(document.createTextNode(" "));
|
node.appendChild(document.createTextNode(" "));
|
||||||
node.appendChild(baselib.format.toDomNode(p, cache));
|
node.appendChild(baselib.format.toDomNode(p, cache));
|
||||||
|
@ -157,13 +157,13 @@
|
||||||
|
|
||||||
|
|
||||||
var isPair = function (x) { return x instanceof Cons; };
|
var isPair = function (x) { return x instanceof Cons; };
|
||||||
var isEmpty = function (x) { return x === Empty.EMPTY; };
|
var isEmpty = function (x) { return x === EMPTY; };
|
||||||
|
|
||||||
|
|
||||||
var makePair = Cons.makeInstance;
|
var makePair = Cons.makeInstance;
|
||||||
|
|
||||||
var makeList = function () {
|
var makeList = function () {
|
||||||
var result = Empty.EMPTY, i;
|
var result = EMPTY, i;
|
||||||
for (i = arguments.length - 1; i >= 0; i--) {
|
for (i = arguments.length - 1; i >= 0; i--) {
|
||||||
result = Cons.makeInstance(arguments[i], result);
|
result = Cons.makeInstance(arguments[i], result);
|
||||||
}
|
}
|
||||||
|
@ -171,10 +171,21 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Coerse a list back into a JavaScript array.
|
||||||
|
var listToArray = function(lst) {
|
||||||
|
var result = [];
|
||||||
|
while (lst !== EMPTY) {
|
||||||
|
result.push(lst.first);
|
||||||
|
lst = lst.rest;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// isList: Any -> Boolean
|
// isList: Any -> Boolean
|
||||||
// Returns true if x is a list (a chain of pairs terminated by EMPTY).
|
// Returns true if x is a list (a chain of pairs terminated by EMPTY).
|
||||||
var isList = function (x) {
|
var isList = function (x) {
|
||||||
while (x !== Empty.EMPTY) {
|
while (x !== EMPTY) {
|
||||||
if (x instanceof Cons) {
|
if (x instanceof Cons) {
|
||||||
x = x.rest;
|
x = x.rest;
|
||||||
} else {
|
} else {
|
||||||
|
@ -229,6 +240,6 @@
|
||||||
exports.reverse = reverse;
|
exports.reverse = reverse;
|
||||||
exports.length = length;
|
exports.length = length;
|
||||||
exports.listRef = listRef;
|
exports.listRef = listRef;
|
||||||
|
exports.listToArray = listToArray;
|
||||||
|
|
||||||
}(this.plt.baselib));
|
}(this.plt.baselib));
|
|
@ -80,6 +80,8 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var EMPTY_PENDING_ACTIONS = plt.baselib.lists.EMPTY;
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// A MockView provides a functional interface to the DOM. It
|
// A MockView provides a functional interface to the DOM. It
|
||||||
|
@ -88,17 +90,25 @@
|
||||||
// freshness of the MockView.
|
// freshness of the MockView.
|
||||||
var MockView = function(cursor, pendingActions, eventHandlers, nonce) {
|
var MockView = function(cursor, pendingActions, eventHandlers, nonce) {
|
||||||
this.cursor = cursor;
|
this.cursor = cursor;
|
||||||
|
|
||||||
|
// (listof (view -> void))
|
||||||
this.pendingActions = pendingActions;
|
this.pendingActions = pendingActions;
|
||||||
|
|
||||||
this.eventHandlers = eventHandlers;
|
this.eventHandlers = eventHandlers;
|
||||||
this.nonce = nonce;
|
this.nonce = nonce;
|
||||||
};
|
};
|
||||||
|
|
||||||
var isMockView = plt.baselib.makeClassPredicate(MockView);
|
var isMockView = plt.baselib.makeClassPredicate(MockView);
|
||||||
|
|
||||||
|
MockView.prototype.getPendingActions = function() {
|
||||||
|
return plt.baselib.lists.listToArray(this.pendingActions).reverse();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
MockView.prototype.act = function(actionForCursor, actionForEventHandlers, actionForReal) {
|
MockView.prototype.act = function(actionForCursor, actionForEventHandlers, actionForReal) {
|
||||||
if (arguments.length !== 3) { throw new Error("act: insufficient arguments"); }
|
if (arguments.length !== 3) { throw new Error("act: insufficient arguments"); }
|
||||||
return new MockView(actionForCursor(this.cursor),
|
return new MockView(actionForCursor(this.cursor),
|
||||||
this.pendingActions.concat([actionForReal]),
|
plt.baselib.lists.makePair(actionForReal, this.pendingActions),
|
||||||
actionForEventHandlers(this.eventHandlers),
|
actionForEventHandlers(this.eventHandlers),
|
||||||
this.nonce);
|
this.nonce);
|
||||||
};
|
};
|
||||||
|
@ -441,7 +451,7 @@
|
||||||
View.prototype.getMockAndResetFocus = function(nonce) {
|
View.prototype.getMockAndResetFocus = function(nonce) {
|
||||||
this.focus = this.top;
|
this.focus = this.top;
|
||||||
return new MockView(domToCursor($(this.top).get(0)),
|
return new MockView(domToCursor($(this.top).get(0)),
|
||||||
[],
|
EMPTY_PENDING_ACTIONS,
|
||||||
this.eventHandlers.slice(0),
|
this.eventHandlers.slice(0),
|
||||||
nonce);
|
nonce);
|
||||||
};
|
};
|
||||||
|
@ -512,14 +522,14 @@
|
||||||
} catch (exn1) {
|
} catch (exn1) {
|
||||||
return onFail(exn1);
|
return onFail(exn1);
|
||||||
}
|
}
|
||||||
return onSuccess(new MockView(domToCursor(dom.get(0)), [], [], undefined));
|
return onSuccess(new MockView(domToCursor(dom.get(0)), EMPTY_PENDING_ACTIONS, [], undefined));
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
dom = $(plt.baselib.format.toDomNode(x));
|
dom = $(plt.baselib.format.toDomNode(x));
|
||||||
} catch (exn2) {
|
} catch (exn2) {
|
||||||
return onFail(exn2);
|
return onFail(exn2);
|
||||||
}
|
}
|
||||||
return onSuccess(new MockView(domToCursor(dom.get(0)), [], [], undefined));
|
return onSuccess(new MockView(domToCursor(dom.get(0)), EMPTY_PENDING_ACTIONS, [], undefined));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1086,7 +1096,7 @@
|
||||||
function(newMockView) {
|
function(newMockView) {
|
||||||
if (newMockView.nonce === nonce) {
|
if (newMockView.nonce === nonce) {
|
||||||
var i;
|
var i;
|
||||||
var actions = newMockView.pendingActions;
|
var actions = newMockView.getPendingActions();
|
||||||
for (i = 0; i < actions.length; i++) {
|
for (i = 0; i < actions.length; i++) {
|
||||||
actions[i](view);
|
actions[i](view);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user