Created
January 16, 2011 23:36
-
-
Save destroytoday/782269 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var menu:NativeMenu = new NativeMenu(); | |
var runner:IRecycleOperationRunner = new RecycleOperationRunner(); | |
var operation:IRecycleOperation = new RecycleOperation(); | |
function updateMenu(menu:NativeMenu, data:Vector.<String>):void | |
{ | |
operation.menu = menu; | |
operation.labelList = labelList; | |
runner.run(operation); | |
} | |
updateMenu(menu, Vector.<(['One', 'Two'])>); // creates 2 items | |
updateMenu(menu, Vector.<(['Red', 'Orange', 'Yellow', 'Green', 'Blue', 'Indigo', 'Violet'])>); // reuses 2, creates 5 | |
updateMenu(menu, Vector.<(['Banana', 'Apple', 'Peach', 'Grape'])>); // reuses 4, disposes 3 to the pool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
public interface IRecycleOperation extends IDisposable | |
{ | |
function get numObjects():int; | |
function get numDataItems():int; | |
function createObject():void; | |
function reuseObject(i:int):void; | |
function setupObject(i:int):void; | |
function removeObject():void; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
public interface IRecycleOperationRunner | |
{ | |
function run(operation:IRecycleOperation):void; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
public class RecycleOperationRunner implements IRecycleOperationRunner | |
{ | |
public function RecycleOperationRunner() | |
{ | |
} | |
public function run(operation:IRecycleOperation):void | |
{ | |
const m:int = Math.max(numObjects, numDataItems); | |
for (var i:int = 0; i < m; i++) | |
{ | |
if (i < numDataItems) | |
{ | |
if (i < numObjects) | |
{ | |
operation.reuseItem(i); | |
} | |
else | |
{ | |
operation.createItem(i); | |
} | |
operation.setupItem(i); | |
} | |
else | |
{ | |
operation.removeItem(i); | |
} | |
} | |
operation.dispose(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment