kopia lustrzana https://github.com/backface/turtlestitch
experiment with new dynamic method (cache) updating
OOP under construction. Possibly to be reverted again, so don’t rely on thisupd4.1
rodzic
d2dee38b34
commit
ab03c81423
|
@ -3380,3 +3380,7 @@ Fixes:
|
|||
170227
|
||||
------
|
||||
* Objects: experiment with new “methods” attribute
|
||||
|
||||
170301
|
||||
------
|
||||
* Objects: experiment with new dynamic method (cache) updating
|
||||
|
|
37
objects.js
37
objects.js
|
@ -82,7 +82,7 @@ SpeechBubbleMorph, RingMorph, isNil, FileReader, TableDialogMorph,
|
|||
BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
|
||||
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, Variable*/
|
||||
|
||||
modules.objects = '2017-February-17';
|
||||
modules.objects = '2017-March-01';
|
||||
|
||||
var SpriteMorph;
|
||||
var StageMorph;
|
||||
|
@ -4936,20 +4936,39 @@ SpriteMorph.prototype.hasSpriteVariable = function (varName) {
|
|||
};
|
||||
|
||||
// SpriteMorph inheritance - custom blocks
|
||||
// +++ under construction
|
||||
// +++ under construction - remember to propagate to StageMorph
|
||||
|
||||
SpriteMorph.prototype.updateMethods = function () {
|
||||
SpriteMorph.prototype.updateMethod = function (aDefinition, spec) {
|
||||
var slot;
|
||||
if (isNil(spec)) {
|
||||
spec = aDefinition.blockSpec();
|
||||
}
|
||||
|
||||
// sanity checks, to be removed after thorough testing
|
||||
if (aDefinition.isGlobal) {
|
||||
throw new Error('cannot update methods with global block');
|
||||
}
|
||||
if (spec === '') {
|
||||
throw new Error('missing spec in definition update');
|
||||
}
|
||||
|
||||
slot = this.methods[spec];
|
||||
if (slot instanceof Variable) {
|
||||
slot.value = aDefinition;
|
||||
} else {
|
||||
slot = new Variable(aDefinition);
|
||||
this.methods[spec] = slot;
|
||||
}
|
||||
return slot;
|
||||
};
|
||||
|
||||
SpriteMorph.prototype.updateAllMethods = function () {
|
||||
var all = this.allBlocks(),
|
||||
methods = this.methods,
|
||||
obsolete;
|
||||
|
||||
Object.keys(all).forEach(function (spec) {
|
||||
var slot = methods[spec];
|
||||
if (slot instanceof Variable) {
|
||||
slot.value = all[spec];
|
||||
} else {
|
||||
methods[spec] = new Variable(all[spec]);
|
||||
}
|
||||
this.updateMethod(all[spec], spec);
|
||||
});
|
||||
|
||||
// remove unused entries
|
||||
|
|
Ładowanie…
Reference in New Issue