From d2dee38b34c41462126446723d3cd2b6d8702303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20M=C3=B6nig?= Date: Mon, 27 Feb 2017 08:18:53 +0100 Subject: [PATCH] =?UTF-8?q?experiment=20with=20new=20=E2=80=9Cmethods?= =?UTF-8?q?=E2=80=9D=20attribute?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … but already planning to perhaps revert this mechanism again… --- history.txt | 4 ++++ objects.js | 45 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/history.txt b/history.txt index 4df39c62..b71b6a28 100755 --- a/history.txt +++ b/history.txt @@ -3376,3 +3376,7 @@ Fixes: 170216 ------ * turn “definition” property of custom block instances into a double-pointer (Variable) structure, in preparation for OOP (method inheritance) + +170227 +------ +* Objects: experiment with new “methods” attribute diff --git a/objects.js b/objects.js index 6d9ff0f5..16903367 100644 --- a/objects.js +++ b/objects.js @@ -80,9 +80,9 @@ document, isNaN, isString, newCanvas, nop, parseFloat, radians, window, modules, IDE_Morph, VariableDialogMorph, HTMLCanvasElement, Context, List, SpeechBubbleMorph, RingMorph, isNil, FileReader, TableDialogMorph, BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize, -TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph*/ +TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, Variable*/ -modules.objects = '2017-February-16'; +modules.objects = '2017-February-17'; var SpriteMorph; var StageMorph; @@ -1375,6 +1375,7 @@ SpriteMorph.prototype.init = function (globals) { // sprite inheritance this.exemplar = null; + this.methods = {}; // not to be serialized, blockSpec: Variable[definition] SpriteMorph.uber.init.call(this); @@ -4935,18 +4936,33 @@ SpriteMorph.prototype.hasSpriteVariable = function (varName) { }; // SpriteMorph inheritance - custom blocks -// under construction +// +++ under construction -/* -SpriteMorph.prototype.ownBlocks = function () { - var dict = {}; - this.customBlocks.forEach(function (def) { - dict[def.blockSpec()] = def; +SpriteMorph.prototype.updateMethods = 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]); + } + }); + + // remove unused entries + obsolete = Object.keys(methods).filter(function (spec) { + return !contains(Object.keys(all), spec); + }); + obsolete.forEach(function (spec) { + methods.delete(spec); }); - return dict; }; SpriteMorph.prototype.allBlocks = function (valuesOnly) { + // private var dict = {}; this.allExemplars().reverse().forEach(function (sprite) { sprite.customBlocks.forEach(function (def) { @@ -4959,7 +4975,17 @@ SpriteMorph.prototype.allBlocks = function (valuesOnly) { return dict; }; +SpriteMorph.prototype.ownBlocks = function () { + // private + var dict = {}; + this.customBlocks.forEach(function (def) { + dict[def.blockSpec()] = def; + }); + return dict; +}; + SpriteMorph.prototype.inheritedBlocks = function (valuesOnly) { + // private var dict = {}, own = Object.keys(this.ownBlocks()), others = this.allExemplars().reverse(); @@ -4977,7 +5003,6 @@ SpriteMorph.prototype.inheritedBlocks = function (valuesOnly) { } return dict; }; -*/ // SpriteMorph thumbnail