Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce event/command naming convention #110

Open
barraq opened this issue Aug 12, 2014 · 0 comments
Open

Introduce event/command naming convention #110

barraq opened this issue Aug 12, 2014 · 0 comments

Comments

@barraq
Copy link
Member

barraq commented Aug 12, 2014

There are actually no event naming convention in Dahu Next and there is a confusion between event and commands.

For better maintainability and readability it is mandatory to introduce a naming convention and apply this convention (this include refactoring the previous events).

The proposed convention is given below.

We use 'Backbone.Wreqr' for handling message passing within Dahu. This extension to backbone reuse backbone event and introduce two new concepts: command and request&answer (see: https://github.com/marionettejs/backbone.wreqr)

Events:

  • ::= ":"
  • ::= | ":"
  • ::=
  • ::=

For use past-tense only when appropriate.

Let's assume that our handler named as onClicked. Since the handler's name saying in past tense we can get a reasonable question: "When clicked, how long ago it happened?     How many times it was clicked? Hmm, maybe it's too late to handle this action (or actions?) at all...". So this name tells us that something happened sometime in past.
In contrast when our handler named as onClick it's obviously that click event just fired and fired once and we was notified about it immediately. And we're going to handle the click event - the information saying us that the state of mouse changed right now (not mouse clicked, but the event of click).
So the names in past tense are more appropriate for the cases when we need to check if some state has been changed or not. E.g. if the variable stores the state = 1 we can call the function isStateChanged(); which will compare the value in state variable with the real value at the current moment. And here the past tense is good choice for naming. (http://stackoverflow.com/a/11990334)

Commands:

  • ::= ":"

Handlers:

  • ::= "on" |
  • ::=
  • ::=

Note: part of the event-name / command-name namespace can be omitted in the resulting handler-name when the module (in which handlers are defined) is in charge of all events / commands from this namespace.

Examples:

Event Name Handler Name
'kernel:keyboard:keyRelease' onKeyRelease()
'app:screencast:cleanComplete' onScreencastCleanComplete()
Command Name Handler Name
'app:workspace:openNote' openNote()
'app:previewScreencast' previewScreencast()
'app:activateFullscreenMode' activateFullScreenMode()

Wrongs:

'app:onCaptureStop' instead use 'app:stopCapture'
'app:onProjectSave' instead use 'app:saveProject'

@barraq barraq added this to the 0.4 (Next) milestone Aug 12, 2014
@barraq barraq changed the title Introduce event naming convention Introduce event/command naming convention Aug 12, 2014
This was referenced Jun 2, 2015
@barraq barraq closed this as completed Jun 5, 2015
@barraq barraq reopened this Jun 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant