{"id":13744032,"url":"https://github.com/darscan/robotlegs-extensions-Oil","last_synced_at":"2025-05-09T02:32:15.568Z","repository":{"id":1130965,"uuid":"1006744","full_name":"darscan/robotlegs-extensions-Oil","owner":"darscan","description":"Oil is a collection of utilities and extensions for the Robotlegs framework","archived":false,"fork":false,"pushed_at":"2012-03-20T18:04:52.000Z","size":297,"stargazers_count":69,"open_issues_count":0,"forks_count":13,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-25T17:32:39.334Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"ActionScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/darscan.png","metadata":{"files":{"readme":"README.textile","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-10-19T18:40:01.000Z","updated_at":"2023-07-25T13:42:15.000Z","dependencies_parsed_at":"2022-08-16T12:10:33.199Z","dependency_job_id":null,"html_url":"https://github.com/darscan/robotlegs-extensions-Oil","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darscan%2Frobotlegs-extensions-Oil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darscan%2Frobotlegs-extensions-Oil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darscan%2Frobotlegs-extensions-Oil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darscan%2Frobotlegs-extensions-Oil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/darscan","download_url":"https://codeload.github.com/darscan/robotlegs-extensions-Oil/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253177784,"owners_count":21866401,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T05:01:01.661Z","updated_at":"2025-05-09T02:32:15.261Z","avatar_url":"https://github.com/darscan.png","language":"ActionScript","funding_links":[],"categories":["Frameworks"],"sub_categories":["RobotLegs Framework"],"readme":"h1. Oil\n\nh2. Overview\n\nOil is a collection of utilities and extensions for the Robotlegs framework.\n\nh2. Async\n\nSome simple tools for dealing with asynchronous operations. May be expanded to include things like Tasks and Schedules.\n\nh3. Promise\n\nA Promise allows you to bind to the result of an asynchronous operation, and has a fluent interface for adding result, error and progress callbacks.\n\nThe status, result, error and progress properties are bindable. Handlers will run even if they are added \"late\" (after-the-fact). A handler must accept a single argument: a Promise.\n\nh4. Consumption\n\nPromise consumption might look like this:\n\n\u003cpre\u003e\n  view.userPromise = service.getUser(userId)\n    .addResultHandler(handler)\n    .addErrorHandler(handler)\n    .addProgressHandler(handler);\n  \n  function handler(p:Promise):void\n  {\n    trace(p.status);\n    trace(p.result);\n    trace(p.error);\n    trace(p.progress);\n  }\n\u003c/pre\u003e\n\n\u003cpre\u003e\n    \u003cfx:Declarations\u003e\n      \u003casync:Promise id=\"userPromise\"/\u003e\n    \u003c/fx:Declarations\u003e\n    \u003cs:DataGroup dataProvider=\"{userPromise.result}\" /\u003e\n\u003c/pre\u003e\n\nh4. Making Promises\n\nA provider might look something like this:\n\n\u003cpre\u003e\n  public function getUser(userId:String):Promise\n  {\n    var promise:Promise = new Promise();\n    // .. wire up some async call that ends up at handleComplete() //\n    return promise;\n  }\n  \n  protected function handleComplete(event:Event):void\n  {\n    var loader:URLLoader = event.target as URLLoader;\n    var promise:Promise = promises[loader];\n    delete promises[loader];\n    promise.handleResult(loader.data);\n  }\n\u003c/pre\u003e\n\nNote: the promises dictionary above is just an example. How you manage Promises from your provider is completely up to you. For a more thorough example see: org.robotlegs.oil.rest.RestClientBase \n\nh4. Processing Promises (updated)\n\nYou might want your provider to process results before calling the result handlers. A processor is an asynchronous function that accepts a data payload and a callback. You must call the callback with an error (or null) as the first argument and the transformed data as the second. \n\n\u003cpre\u003e\n  public function getUser(userId:String):Promise\n  {\n    var promise:Promise = new Promise()\n      .addResultProcessor(jsonProcessor)\n      .addResultProcessor(timestampProcessor)\n      .addResultProcessor(throttleProcessor);\n    // .. snip .. //\n    return promise;\n  }\n  \n  function jsonProcessor(input:String, callback:Function):void\n  {\n    var data:Object = new JSONDecoder().decode(input);\n    if (data \u0026\u0026 data.error)\n    {\n      callback(data.error);\n    }\n    else\n    {\n      callback(null, output);\n    }\n  }\n  \n  function timestampProcessor(input:Object, callback:Function):void\n  {\n    var output:Object = input;\n    output.timestamp = new Date().time;\n    callback(null, output);\n  }\n  \n  function throttleProcessor(data:Object, callback:Function):void\n  {\n    setTimeout(function():void\n    {\n      callback(null, data);\n    }, 500);\n  }\n\u003c/pre\u003e\n\nNote: You *must* call the callback at some point.\n\nNote: Passing any non-falsey value as the first argument to the callback will halt processing, put the promise into the failed state and invoke any error handlers.\n\nh2. Rest\n\nAn IRestClient returns Promises from get, post, put and delete calls.\n\n\u003cpre\u003e\n  client = new JSONClient(\"http://api.somewhere.com\");\n  view.userPromise = client.get(\"/user/\" + userId)\n    .addResultHandler(onUser)\n    .addErrorHandler(onUserError)\n    .addProgressHandler(onUserProgress);\n\u003c/pre\u003e\n\nA service might look something like this:\n\n\u003cpre\u003e\npublic class UserService\n{\n  protected var service:IRestClient;\n  \n  public function UserService(service:IRestClient)\n  {\n    this.service = service;\n  }\n\n  public function getUsers():Promise\n  {\n    return service.get('/users/');\n  }\n\n  public function getUserDetails(userId:String):Promise\n  {\n    return service.get('/users/' + userId);\n  }\n}\n\u003c/pre\u003e\n\nh2. Pool\n\nBasic object pooling.\n\n\u003cpre\u003e\n  pool = new BasicObjectPool(MyRenderer, {someProp:\"hello\"});\n  object = pool.get();\n  pool.put(object);\n  pool.ensureSize(10);\n\u003c/pre\u003e\n\n\u003cpre\u003e\n  pool = new InjectingObjectPool(injector, MyRenderer, {someProp:\"hello\"});\n  object = pool.get();\n\u003c/pre\u003e\n\nh2. Flex\n\nSome Flex-specific stuff, like IFactory implementations that pull instances from DI containers or object pools.\n\nh3. InjectingFactory\n\nA Flex IFactory implementation that pulls objects from a Robotlegs IInjector.\n\n\u003cpre\u003e\n  list.itemRenderer = new InjectingFactory(injector, MyRenderer, {someProp:\"hello\"});\n\u003c/pre\u003e\n\nh3. InjectingFactoryBuilder\n\nBuilds an InjectingFactory pre-configured with an Injector.\n\n\u003cpre\u003e\n  builder = new InjectingFactoryBuilder(injector);\n  list.itemRenderer = builder.build(MyRenderer, {someProp:\"hello\"});\n\u003c/pre\u003e\n\nh3. PooledRendererFactory, PooledRendererFactoryProvider\n\nA Flex IFactory implementation that pulls objects from an object pool.\n\n\u003cpre\u003e\n  pool = new InjectingObjectPool(injector, MyRenderer, {someProp:\"hello\"});\n  list.itemRenderer = new PooledRendererFactory(pool);\n\u003c/pre\u003e\n\nIncludes a mechanism for pooling data renderers across multiple consumers.\n\n\u003cpre\u003e\n  \u003cs:DataGroup id=\"list\"\n    typicalItem=\"{prFactory.newInstance()}\"\n    itemRenderer=\"{prFactory}\"\n    itemRendererFunction=\"{prFactory.itemRendererFunction}\"\n    rendererRemove=\"prFactory.rendererRemoveHandler(event)\" /\u003e\n\u003c/pre\u003e\n\nAlternatively\n\n\u003cpre\u003e\n  provider = new PooledRendererFactoryProvider(injector);\n  provider\n    .getFactory(MyRenderer)\n    .manage(list);\n\u003c/pre\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarscan%2Frobotlegs-extensions-Oil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarscan%2Frobotlegs-extensions-Oil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarscan%2Frobotlegs-extensions-Oil/lists"}