Skip to content

Commit 8cdc5ea

Browse files
committed
Change PaperScope#install() to be clever about project, view and tool references and link them through a getter to their current state in PaperScope.
1 parent 3fc21cd commit 8cdc5ea

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/core/PaperScope.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,22 @@ var PaperScope = this.PaperScope = Base.extend(/** @lends PaperScope# */{
126126
* paper.install(window);
127127
*/
128128
install: function(scope) {
129+
// Define project, view and tool as getters, so they are kept up to date
130+
var that = this;
131+
Base.each(['project', 'view', 'tool'], function(key) {
132+
Base.define(scope, key, {
133+
configurable: true,
134+
writable: true,
135+
get: function() {
136+
return that[key];
137+
}
138+
});
139+
});
129140
// Use scope as side-car (= 'this' inside iterator), and have it
130141
// returned at the end.
131142
return Base.each(this, function(value, key) {
132-
this[key] = value;
143+
if (!(key in this))
144+
this[key] = value;
133145
}, scope);
134146
},
135147

0 commit comments

Comments
 (0)