Lively Kernel canvas
// this script is evaluated on world load
module("MyWorkspaceLayer").requires(["lively.Text", "cop.Layers"]).toRun(function() {
Object.extend(Morph.prototype, LayerableObjectTrait);
Morph.prototype.lookupLayersIn = ["owner"];
// Debugging Behavior
createLayer("WorkspaceLayer");
layerClass(WorkspaceLayer, TextMorph, {
toggleEvalOnWorldLoad: function() {
this.evalOnWorldLoad = ! this.evalOnWorldLoad;
},
onDeserialize: function(proceed) {
proceed();
console.log("eval workspace");
if (this.evalOnWorldLoad) {
this.tryBoundEval(this.textString);
}
},
})
// Static Instrumentatioan
createLayer("WorkspaceControlLayer");
layerClass(WorkspaceControlLayer, WindowMorph, {
isWorkspaceLayerEnabled: function() {
var layers = this.getWithLayers();
return layers && layers.include(WorkspaceLayer);
},
toggleWorkspace: function() {
console.log("this= " + this);
if (this.isWorkspaceLayerEnabled()) {
console.log("disable workspace for " + this);
this.setWithLayers([]);
} else {
console.log("enable workspace for " + this);
this.setWithLayers([WorkspaceLayer]);
}
},
askForNewTitle: function() {
var self = this;
WorldMorph.current().prompt('new name', function(input) {
self.setTitle(input)
})
},
morphMenu: function(proceed, evt) {
console.log("morph menu : ")
var menu = proceed(evt);
if (menu) {
menu.addItem([
"change title", this,
'askForNewTitle']);
menu.addItem([
(this.isWorkspaceLayerEnabled() ? "disable" : "enable") +
" workspace", this,
'toggleWorkspace']);
}
return menu
}
})
enableLayer(WorkspaceControlLayer);
console.log("finished loading workspace code")
// disableLayer(DebugMorphMenuLayer);
})
2.ScopedBehaviorAdaptations40
forbasecode,seelocalcodebrowser14
10000.34867947537392135Wikicontroltrue
-------------------------------------------falsetruefalse0
invoke1:WorldMorph([0,0,1248,664])falsetruefalse0
status200onGEThttp://lively-kernel.org/repository/webwerkstatt/ContextJSScopeExamples.xhtmlfalsetruefalse0
extendForSerializationundefinedfalsetruefalse0
status204onPUThttp://lively-kernel.org/repository/webwerkstatt/ContextJSScopeExamples.xhtmlfalsetruefalse0
successpublishingworldathttp://lively-kernel.org/repository/webwerkstatt/ContextJSScopeExamples.xhtml,status204falsetruefalse0
status:ReferenceError:Can'tfindvariable:ofalsetruefalse0
removestatusfalsetruefalse0
LayerMyLayerisalreadytherefalsetruefalse0
status:ReferenceError:Can'tfindvariable:staticLayerClassfalsetruefalse0
removestatusfalsetruefalse0
status:ReferenceError:Can'tfindvariable:staticLayerClassfalsetruefalse0
removestatusfalsetruefalse0
status:ReferenceError:Can'tfindvariable:staticLayerClassfalsetruefalse0
Can'tfindcurrentpositionintextfalsetruefalse0
removestatusfalsetruefalse0
status:ReferenceError:Can'tfindvariable:staticLayerClassfalsetruefalse0
removestatusfalsetruefalse0
status:TypeError:Resultofexpression'module("MyModule").requiresLayer'[undefined]isnotafunction.falsetruefalse0
removestatusfalsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
inscope:7falsetruefalse0
status:TypeError:Resultofexpression'o.setWithLayers'[undefined]isnotafunction.falsetruefalse0
removestatusfalsetruefalse0
Can'tfindcurrentpositionintextfalsetruefalse0
-------------------------------------------falsetruefalse0
invoke1:WorldMorph([0,0,1248,664])falsetruefalse0
status200onGEThttp://lively-kernel.org/repository/webwerkstatt/ContextJSScopeExamples.xhtmlfalsetruefalse0
extendForSerializationundefinedfalsetruefalse0821-1nulltrue0falsefalsetruetruefalse
false1truefalse
nullfalse
nullfalse
nullfalse
nullfalsefalsetruetruefalse
true100false
truefalsenull050
nullfalsetruenullfalse
Consolefalsenullfalse
false
false
falsenullfalsefalsenullnullnullnullfalse
10000.12157666441798107Wikicontroltrue
10000.13508517176729928Wikicontroltrue
10001.6368977137600462Wikicontroltrue
//BasebehaviorObject.subclass("MyClass",{m:function(){return3}});o=newMyClass();o.m();//3//BehaviorAdaptationcreateLayer("MyLayer");layerClass(MyLayer,MyClass,{m:function(proceed){returnproceed()+4}});//GlobalactivationenableLayer(MyLayer)o.m();disableLayer(MyLayer)//Staticscope//staticallyscopedvariablelookup(function(){vara=3;g=function(){returna}})()//staticallyscopedbehavioradaptation//isnotimplementedmodule("MyModule").requiresLayer("MyLayer").toRun(function(){varo=newMyClass();o.m()//7})//DynamicscopewithLayers([MyLayer],function(){console.log("inscope:"+o.m());//7})o.m()//Object-specificscope//Basicaproach:objectcomputesactivelayerso.getActivatedLayers=function(){return[MyLayer]}o.m()deleteo.getActivatedLayers//Syntacticsuggar?//1.LayerAssignmentObject.extend(MyClass.prototype,LayerableObjectTrait)o.m()//3o.setWithLayers([MyLayer]);o.m()//7//1.ImplicitLayeractivationLayerAssignmento2=newMyClass();o2.parent=o;o2.m()//3MyClass.prototype.lookupLayersIn=["parent"];o2.m();//7//obejct-specificlayeractivationpropagates....o3=newMyClass();o3.parent=o2;o3.m()//7//1.Nonactivationo.setWithLayers([]);o3.m()//3//2.explicitscopecontrolwithdeactivationo.setWithLayers([MyLayer]);o3.m()//7o2.setWithoutLayers([MyLayer]);o3.m()//3console.log("finishedloadingworkspace")
nulltruetruetruefalsetrue80truetruefalse
false1truefalsenulltruetruefalse
nullfalsetruenullfalse
myworkspacefalsenullfalse
false
false
falsenullfalsefalsenullnullnullnullfalse
null51