mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Simplify adding / referencing of JSON dictionary entries.
This commit is contained in:
parent
e477c49d1e
commit
15554b8bf2
3 changed files with 17 additions and 12 deletions
|
@ -34,8 +34,10 @@ var Gradient = this.Gradient = Base.extend(/** @lends Gradient# */{
|
|||
},
|
||||
|
||||
_serialize: function(dictionary) {
|
||||
return dictionary.get(this) || dictionary.set(this, Base.serialize(
|
||||
[this._type, this._stops, this.type], true, dictionary));
|
||||
return dictionary.add(this, function() {
|
||||
return Base.serialize([this._type, this._stops, this.type],
|
||||
true, dictionary);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -259,14 +259,15 @@ this.Base = Base.inject(/** @lends Base# */{
|
|||
length: 0,
|
||||
definitions: {},
|
||||
references: {},
|
||||
get: function(item) {
|
||||
return this.references['#' + item._id];
|
||||
},
|
||||
set: function(item, json) {
|
||||
this.length++;
|
||||
var id = '#' + item._id;
|
||||
this.definitions[id] = json;
|
||||
return this.references[id] = [id];
|
||||
add: function(item, create) {
|
||||
var id = '#' + item._id,
|
||||
ref = this.references[id];
|
||||
if (!ref) {
|
||||
this.length++;
|
||||
this.definitions[id] = create.call(item);
|
||||
ref = this.references[id] = [id];
|
||||
}
|
||||
return ref;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -69,8 +69,10 @@ var Symbol = this.Symbol = Base.extend(/** @lends Symbol# */{
|
|||
},
|
||||
|
||||
_serialize: function(dictionary) {
|
||||
return dictionary.get(this) || dictionary.set(this, [this._type,
|
||||
Base.serialize(this._definition, false, dictionary)]);
|
||||
return dictionary.add(this, function() {
|
||||
return Base.serialize([this._type, this._definition],
|
||||
false, dictionary);
|
||||
});
|
||||
},
|
||||
|
||||
// TODO: Symbol#remove()
|
||||
|
|
Loading…
Reference in a new issue