Lively Kernel canvas
ImplicitLayerActivation40true
"Tosupportthemostgeneralcase,PyContextevaluatestheactivationconditiononeachmethodinvocationofamethodpotentiallyaffectedbylayeractivation.Thatmayproducealotofoverhead;toreducethatoverhead,thelayerdefinitionmayapplycachingtechniquesincaserecomputationoftheconditionisnotnecessaryeverytime."[Loewis2007COP]145
Weseethatinprinciple,wecanimplementimplicitlayerswithourapproachbylettingtheobjectsasksthelayersiftheyareactive.1.Problem,tobegeneralthelayerscopingstrategy(implicitlayeractivation)hastobesharedbyallobjects(forexamplebyimplementingitintherootsuperclass)2.Problem,theactiveLayersmethodsneedsmetainformation(suchascurrentselectorandclass)toreducethenumberoftimesalayerhastobeaskedifitisactive1410
Wikicontroltruetrue
Object.subclass('ImplicitLayerableObject',{activeLayers:function(){//IthinkLoewisgoesfurtherhere,heonly//askslayersiftheclasshaslayeredmethodsforthislayerreturncop.implicitLayers.select(function(ea){returnea.active()})},foo:function(){return1},})cop.create('MyImplicitLayer').refineClass(ImplicitLayerableObject,{foo:function(){return2}})varcounter=0;MyImplicitLayer.active=function(){returncounter++%2==0}cop.implicitLayers=[MyImplicitLayer]o=newImplicitLayerableObject();[o.foo(),o.foo(),o.foo(),o.foo()]//[2,1,2,1]
truetruefalse12truetruefalse
false1truefalsetruetruefalse
nullfalsetruenullfalse
falsenullfalse
false
false
falsenullfalsefalsenullnullnullnullfalse
null77