{"id":13744042,"url":"https://github.com/Stray/robotlegs-utilities-RelaxedEventMap","last_synced_at":"2025-05-09T02:32:17.991Z","repository":{"id":1178086,"uuid":"1075994","full_name":"Stray/robotlegs-utilities-RelaxedEventMap","owner":"Stray","description":"Just what it says - a robotlegs eventMap that lets you be a little more relaxed about race conditions and late-arriving views","archived":false,"fork":false,"pushed_at":"2010-11-22T19:47:07.000Z","size":527,"stargazers_count":17,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-15T15:41:49.895Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Stray.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-11-12T22:25:07.000Z","updated_at":"2017-01-24T19:56:23.000Z","dependencies_parsed_at":"2022-08-16T12:25:28.888Z","dependency_job_id":null,"html_url":"https://github.com/Stray/robotlegs-utilities-RelaxedEventMap","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/Stray%2Frobotlegs-utilities-RelaxedEventMap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stray%2Frobotlegs-utilities-RelaxedEventMap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stray%2Frobotlegs-utilities-RelaxedEventMap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stray%2Frobotlegs-utilities-RelaxedEventMap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Stray","download_url":"https://codeload.github.com/Stray/robotlegs-utilities-RelaxedEventMap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253177786,"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.870Z","updated_at":"2025-05-09T02:32:17.138Z","avatar_url":"https://github.com/Stray.png","language":"ActionScript","funding_links":[],"categories":["Frameworks"],"sub_categories":["RobotLegs Framework"],"readme":"**What's it so relaxed about?** \n\nSometimes, race conditions, or dynamic view creation, mean that a mediator only registers for a data event after the event has fired.\nCommon workarounds include injecting your model into your mediator. Yuk! \n\nThe RelaxedEventMap allows you to take your time over adding your views and registering for events. \n\nWhen you mapRelaxedListener it will check whether it has previously received an instance of that particular event \u0026 type. If it has then the event is redispatched _only_ to the handler that is being registered.\n\nThink of mapRelaxedListener as 'I'd like to listen for this event in future, oh - and if it has already happened then I'd like to get that most recent event right now as well please'.  It's like listening back into the past, but only for the most recent occurrence.\n\n\n**Compatibility**\n\nRobotlegs utility, tested against robotlegs v1.0 thru 1.4\n\nFull test coverage is provided with asunit 3.\n\nNo swc as you should compile from source to ensure it extends the same version of robotlegs as the rest of your project.\n\n\n**Usage:**     \n\nIn your context:\n\t\n\t// implement this interface:\n\timport org.robotlegs.core.IRelaxedEventContext;\n\t\n\tprotected var _relaxedEventMap:IRelaxedEventMap;\n\t\n\tpublic function get relaxedEventMap():IRelaxedEventMap\n\t{\n\t\treturn _relaxedEventMap ||= new RelaxedEventMap(eventDispatcher);\n\t}\n\t\n\tpublic function set relaxedEventMap(value:IRelaxedEventMap):void\n\t{\n\t\t_relaxedEventMap = value;\n\t}\n\t\n\toverride protected function mapInjections():void\n\t{\n\t\tsuper.mapInjections();\n\t\tinjector.mapValue(IRelaxedEventMap, relaxedEventMap);\n\t}\n\t\n\nIt is also necessary to add a dummy handler to tell the relaxedEventMap to pick up this event.\nYou can do this in your context startup, or in a dedicated bootstrap Command.                            \n\n\t// using a dedicated method that creates an empty listener for you\n\trelaxedEventMap.rememberEvent(SomeDataEvent.DATA_SET_UPDATED, SomeDataEvent);\n    \n\t// or manually - for example so you can trace or log the event in the function passed here\n\trelaxedEventMap.mapRelaxedListener(SomeDataEvent.DATA_SET_UPDATED, function():void{}, SomeDataEvent);\n       \n\nWhere you want to ensure the mediator receives the event, even if onRegister runs _after_ it has been fired.\nNote that the parameters are similar to mapListener, but the dispatcher is always the shared eventDispatcher.\n    \n\t// first - inject the relaxedEventMap\n\t[Inject]\n\tpublic var relaxedEventMap:IRelaxedEventMap;\n\t\n\t// then\n\tpublic override function onRegister():void\n\t{\n    \trelaxedEventMap.mapRelaxedListener(SomeDataEvent.DATA_SET_UPDATED, handler, SomeDataEvent);\n    }\n       \n\n**Clean up**\n\nIn most other respects the RelaxedEventMap behaves just like the normal eventMap. The key difference is that there is only one RelaxedEventMap, where your individual mediators each have their own eventMap. If you need to de-register for the event when your view leaves the stage:\n\n\t// in the mediator, override preRemove\n\tpublic override function preRemove():void\n\t{\n\t\trelaxedEventMap.unmapRelaxedListener(SomeDataEvent.DATA_SET_UPDATED, handler, SomeDataEvent);\n\t}\n\t\n\t\n** Passing the owner mediator for easier cleanup **\n\nYou can pass the mediator instance as an additional optional parameter when you mapRelaxedListener which then allows you to unmap all the listeners for that mediator (or object) in one go.\n\n\t// pass the mediator 'this' as the ownerObject\n\trelaxedEventMap.mapRelaxedListener(SomeDataEvent.DATA_SET_UPDATED, updatedHandler, SomeDataEvent, this);\n\trelaxedEventMap.mapRelaxedListener(SomeDataEvent.DATA_SET_DELETED, deletedHandler, SomeDataEvent, this);    \n\t\n\t// remove all the listeners for this mediator in one go:\n\tpublic override function preRemove():void\n\t{\n\t\trelaxedEventMap.unmapListenersFor(this);\n\t}\n\n\n**Warnings**\n\nBecause the relaxedEventMap is shared across mediators, be very careful before using 'unmapListeners' (as inherited from EventMap) as this will remove *all* the listeners, including the dummy ones set up using rememberEvent.\n\nYou could potentially still wish to use this approach in - for example - the clean-up of a module being unloaded from your application - hence it is still available, but should only be used with caution.\n  ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FStray%2Frobotlegs-utilities-RelaxedEventMap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FStray%2Frobotlegs-utilities-RelaxedEventMap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FStray%2Frobotlegs-utilities-RelaxedEventMap/lists"}