mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
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:
parent
3fc21cd4b6
commit
8cdc5ea2aa
1 changed files with 13 additions and 1 deletions
|
@ -126,10 +126,22 @@ var PaperScope = this.PaperScope = Base.extend(/** @lends PaperScope# */{
|
||||||
* paper.install(window);
|
* paper.install(window);
|
||||||
*/
|
*/
|
||||||
install: function(scope) {
|
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
|
// Use scope as side-car (= 'this' inside iterator), and have it
|
||||||
// returned at the end.
|
// returned at the end.
|
||||||
return Base.each(this, function(value, key) {
|
return Base.each(this, function(value, key) {
|
||||||
this[key] = value;
|
if (!(key in this))
|
||||||
|
this[key] = value;
|
||||||
}, scope);
|
}, scope);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue