demo

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
demo [2010/03/16 21:51]
aspectscript
demo [2010/03/16 22:26] (current)
aspectscript
Line 14: Line 14:
         <textarea id="code" name="code" style="width:720px; height:441px">//enter your code here</textarea>         <textarea id="code" name="code" style="width:720px; height:441px">//enter your code here</textarea>
         </div>         </div>
-        <div style="float: rigth;"> +        <div style="float: rigth; text-align: left; margin-left: 10px;"> 
-          <a href="javascript:setCode('step0');">Step 0: removeTag code</a> +          <p>Step 0:<br><a href="javascript:setCode('step0');">removeTag code</a></p> 
-          <a href="javascript:setCode('actionAspect');">Action Aspect</a><br>+<hr
 +          <p>Step 1:<br><a href="javascript:setCode('step1');">Aspect Structure</a></p> 
 +<hr> 
 +          <p>Step 2:<br><a href="javascript:setCode('step2');">Batch Aspect</a></p> 
 +<hr> 
 +          <p>Step 3:<br><a href="javascript:setCode('step3');">RemoveAll Aspect</a></p>
  
-          <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>+<hr> 
 +          <p>Step 4:<br><a href="javascript:setCode('step4');">Everything together</a></p> 
 + 
 +<hr> 
 + 
 +         <p>Step 5:<br><a href="javascript:setCode('step5');">Everything together (2)</a></p> 
 + 
 +          <br>
           <input type="submit" value="  Run it!  ">           <input type="submit" value="  Run it!  ">
         </div>                 </div>        
Line 54: Line 66:
  
     <div style="display:none;">     <div style="display:none;">
-  <pre id="actionAspect">+  <pre id="step0">
 function removeTag(userID, photoID){ function removeTag(userID, photoID){
     alert("Removed from pic #" + photoID);     alert("Removed from pic #" + photoID);
 } }
     </pre>     </pre>
-    <pre id="actionAspect"> +    <pre id="step1"> 
-var actionListAspect = AspectScript.deploy({+AspectScript.deploy({ 
 +    kind:  
 +    pointcut:  
 +    advice:  
 +}); 
 +    </pre> 
 +    <pre id="step2"> 
 +var batchAspect = AspectScript.deploy({
     kind: AspectScript.AROUND,     kind: AspectScript.AROUND,
     pointcut: function(jp){     pointcut: function(jp){
Line 72: Line 91:
     removals: [],     removals: [],
     applyChanges: function(){     applyChanges: function(){
-        for(var i = 0; i < this.removals.length; ++i){ +        while(this.removals.length != 0){ 
-            this.removals[i].proceed();+            this.removals.shift().proceed(); 
 +        } 
 +    } 
 +}); 
 +    </pre> 
 + 
 +<pre id="step3"> 
 +var removeAllAspect = AspectScript.deploy({ 
 +    kind: AspectScript.AFTER, 
 +    pointcut: AspectScript.Pointcuts.call(removeTag).and(function(jp){ 
 +        this.removedIds.push(jp.args[1]); 
 +        return this.removedIds.length >= 3; 
 +    }), 
 +    advice: function(){ 
 +        if(confirm("Would you like to remove all tags from current album?")){ 
 +            for(var i = 1; i <= 5; ++i){ 
 +                if(this.shouldRemove(i)){ 
 +                    removeTag(1, i); 
 +                } 
 +            } 
 +        } 
 +    }, 
 +    //other properties 
 +    removedIds: [], 
 +    shouldRemove: function(idx){ 
 +        for(var i = 0; i < this.removedIds.length; ++i){ 
 +            if(this.removedIds[i] == idx){ 
 +                return false; 
 +            } 
 +        } 
 +        return true; 
 +    } 
 +}); 
 +    </pre> 
 + 
 +  <pre id="step4"> 
 +var batchAspect = AspectScript.deploy({ 
 +    kind: AspectScript.AROUND, 
 +    pointcut: function(jp){ 
 +        return jp.isCall() && jp.fun === removeTag; 
 +    }, 
 +    advice: function(jp){ 
 +        this.removals.push(jp.clone()); 
 +        updateActionsUI(); 
 +    }, 
 +    //other properties 
 +    removals: [], 
 +    applyChanges: function(){ 
 +        while(this.removals.length != 0){ 
 +            this.removals.shift().proceed(); 
 +        } 
 +    } 
 +}); 
 + 
 +var removeAllAspect = AspectScript.deploy({ 
 +    kind: AspectScript.AFTER, 
 +    pointcut: AspectScript.Pointcuts.call(removeTag).and(function(jp){ 
 +        this.removedIds.push(jp.args[1]); 
 +        return this.removedIds.length >= 3; 
 +    }), 
 +    advice: function(){ 
 +        if(confirm("Would you like to remove all tags from current album?")){ 
 +            for(var = 1; i <= 5; ++i){ 
 +                if(this.shouldRemove(i)){ 
 +                    removeTag(1, i); 
 +                } 
 +            } 
 +        } 
 +    }, 
 +    //other properties 
 +    removedIds: []
 +    shouldRemove: function(idx){ 
 +        for(var i = 0; i < this.removedIds.length; ++i){ 
 +            if(this.removedIds[i] == idx){ 
 +                return false; 
 +            } 
 +        } 
 +        return true; 
 +    } 
 +}); 
 +    </pre> 
 + 
 +  <pre id="step5"> 
 +var batchAspect = AspectScript.deploy({ 
 +    kind: AspectScript.AROUND, 
 +    pointcut: function(jp){ 
 +        return jp.isCall() && jp.fun === removeTag; 
 +    }, 
 +    advice: function(jp){ 
 +        this.removals.push(jp.clone()); 
 +        updateActionsUI(); 
 +    }, 
 +    //other properties 
 +    removals: [], 
 +    applyChanges: function(){ 
 +        while(this.removals.length != 0){ 
 +            this.removals.shift().proceed(); 
 +        } 
 +    } 
 +}); 
 + 
 +var removeAllAspect = AspectScript.deploy({ 
 +    kind: AspectScript.AFTER, 
 +    pointcut: AspectScript.Pointcuts.call(removeTag).and(function(jp){ 
 +        this.removedIds.push(jp.args[1]); 
 +        return this.removedIds.length >= 3; 
 +    }), 
 +    advice: function(){ 
 +        if(confirm("Would you like to remove all tags from current album?")){ 
 +            AspectScript.down(this, function(){ 
 +                for(var i = 1; i <= 5; ++i){ 
 +                    if(this.shouldRemove(i)){ 
 +                        removeTag(1, i); 
 +                    } 
 +                } 
 +            }); 
 +        } 
 +    }, 
 +    //other properties 
 +    removedIds: [], 
 +    shouldRemove: function(idx){ 
 +        for(var i = 0; i < this.removedIds.length; ++i){ 
 +            if(this.removedIds[i] == idx){ 
 +                return false; 
 +            }
         }         }
 +        return true;
     }     }
 }); });
  • demo.1268776291.txt.gz
  • Last modified: 2010/03/16 21:51
  • by aspectscript