Change PaperScope#install() to be clever about project, view and tool references and link them through a getter to their current state in PaperScope.

This commit is contained in:
Jürg Lehni 2011-08-01 11:21:22 +01:00
parent 3fc21cd4b6
commit 8cdc5ea2aa

View file

@ -126,10 +126,22 @@ var PaperScope = this.PaperScope = Base.extend(/** @lends PaperScope# */{
* paper.install(window);
*/
install: function(scope) {
// Define project, view and tool as getters, so they are kept up to date
var that = this;
Base.each(['project', 'view', 'tool'], function(key) {
Base.define(scope, key, {
configurable: true,
writable: true,
get: function() {
return that[key];
}
});
});
// Use scope as side-car (= 'this' inside iterator), and have it
// returned at the end.
return Base.each(this, function(value, key) {
this[key] = value;
if (!(key in this))
this[key] = value;
}, scope);
},