{"id":17772737,"url":"https://github.com/jamesplease/backbone.class-event-spec","last_synced_at":"2025-04-01T15:21:45.507Z","repository":{"id":16442702,"uuid":"19194382","full_name":"jamesplease/backbone.class-event-spec","owner":"jamesplease","description":"(WIP) A specification for handling important events in Backbone Classes.","archived":false,"fork":false,"pushed_at":"2014-04-29T23:02:07.000Z","size":165,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-07T09:42:03.373Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"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/jamesplease.png","metadata":{"files":{"readme":"README.md","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":"2014-04-27T03:03:21.000Z","updated_at":"2023-03-10T08:28:26.000Z","dependencies_parsed_at":"2022-07-13T16:44:50.387Z","dependency_job_id":null,"html_url":"https://github.com/jamesplease/backbone.class-event-spec","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/jamesplease%2Fbackbone.class-event-spec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesplease%2Fbackbone.class-event-spec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesplease%2Fbackbone.class-event-spec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesplease%2Fbackbone.class-event-spec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamesplease","download_url":"https://codeload.github.com/jamesplease/backbone.class-event-spec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246660090,"owners_count":20813339,"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-10-26T21:40:36.144Z","updated_at":"2025-04-01T15:21:45.487Z","avatar_url":"https://github.com/jamesplease.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"Class Event Specs\n====================\n\nThe specifications for Marionette Class Events.\n\n### About\n\nMany Marionette Classes have important events that happen to them. An example is a region showing a view within its\nelement. Those familiar with Marionette know that there is a before and after event associated with this Class Event,\nand also before and after callbacks. This collection of activities around the primary event is collectively called a Class Event.\n\nThese specifications provide the guidelines on how to create a new Class Event for your Classes that follow this same pattern.\n\nThe internal methods of Marionette should **always** adhere to these specifications, and it is highly recommended\nthat you, in your application, also follow the specs.\n\n### Precedent\n\nThe precedent for Class Events is the Backbone Event system, and, in particular, [the built-in list\nof Events](http://backbonejs.org/#Events-catalog). At all times the Class Events specifications should\nbe consistent with that catalogue of events. Should Backbone's event system change, then the Class Events\nspecification should also change to remain consistent.\n\nBecause of this precedent we will begin by studying Backbone Events in greater depth:\n\n#### Anatomy of a Backbone Event\n\nEvents in the Backbone universe follow the following format:\n\n`action:subject`\n\n##### Action\n\nThe action is always present tense. The action should be a simple verb that describes the event\nthat just happened.\n\n```js\n// Bad Backbone event name\n'rendered:view';\n\n// Good Backbone event name\n'render:view';\n```\n\n##### The Separator\n\nThe separator in events is a colon, `:`. The colon should be used instead of other\nseparation mechanisms, such as hyphenating and camelcase.\n\n```js\n// Events that use an incorrect separator\n'show:myView';\n'show:my-view';\n\n// Events that use a correct separator\n'show:my:view';\n```\n\n##### Subject\n\nIf the action is acting on a particular thing, then you may pass along the subject which is separated from the\naction by a colon. Keep in mind that the subject is always optional. An event may have at most\na single subject.\n\nThe subject is ideally a simple, one-word noun. In the case of a more complex noun you should use colons\nto separate out the pieces.\n\n```js\n// If you must use more complex nouns use the colon separator\n'show:scrolling:view';\n```\n\nIt is suggested that you avoid composite nouns if possible.\n\n### Class Events\n\n#### Anatomy of a TriggerMethod\n\nEvery Class Event is wrapped by two triggerMethod calls: one before the event and one afterward. TriggerMethod\ntriggers the event on the class' event bus while also executing a function for that event. So, for instance, \n\nTriggerMethod events differs slightly from Backbone events. They have the following form:\n\n`adverb:verb:subject`\n\n##### Adverb\n\nThe adverb is either `before` or nothing at all.\n\n#### Synchronous/Asynchronous\n\nTrigger Methods events are asynchronous. This means that asynchronous methods in the `onBefore` callback will\nnot be necessarily be executed before the event itself occurs.\n\n#### Anatomy of a Class Event\n\nA class event has three components.\n\n1. A before triggerMethod event\n2. The event itself\n2. An after triggerMethod event\n\n##### The Before TriggerMethod\n\nThe before event callback has the following form\n\n`before:action:subject`\n\nThis causes the following method to be triggered:\n\n`onBeforeActionSubject`\n\n##### The Event Itself\n\nThe event itself is whatever action is being completed. This takes place in-between the trigger method calls.\n\n##### The After TriggerMethod\n\nThe after event callback has the same form as a Backbone event.\n\n`action:subject`\n\nThis causes the following method to be triggered:\n\n`onActionSubject`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesplease%2Fbackbone.class-event-spec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamesplease%2Fbackbone.class-event-spec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesplease%2Fbackbone.class-event-spec/lists"}