Here are the rules that I'm following when choosing names for custom
events (those are by no means standard):
- event name should start with 'on' word
- event name should be prepended with the name of the module that
fires it, followed by '->'
- event name should describe what happend, not what should happen when it fires
For example if keyboard.js module is responsible for handling keyboard
input and user has entered certain
combination of keys, I fire 'keyboard->onSecretCodeEntered' event from
keyboard.js:
> sandbox.fireEvent('keyboard->onSecretCodeEntered', 'konamiCode');
... and then I'm listening for this event from other modules with:
> sandbox.listenEvent('keyboard->onSecretCodeEntered', function(codeType) {
> if (codeType === 'konamiCode') {
> // do stuff here
> }
> });
On Sun, Aug 21, 2011 at 5:26 PM, Xavier MONTILLET
<[email protected]> wrote:
> sandbox.events.say({
> event: "drop",
> data: {
> "id": 3,
> "coordinates": {
> "x": 25,
> "y": 69
> },
> target: 'icon'
> }
> })
>
> I'd say you should use a single verb as event.
> If your event's name starts looking like a sentence, keep the verb and
> move the rest to the data as properties.
>
> On Sun, Aug 21, 2011 at 9:10 AM, manakor <[email protected]> wrote:
>> Hi guys,
>> Recently I have build a sample JS Architecture (inspired by N. Zakas
>> presentation on Yahoo) to my project, which contains single
>> encapsulated modules (based in JS module pattern). Each module has
>> limited knowledge about himself, but he is able to throw
>> notifications, which could be read by other modules.
>>
>> I started to work on the project, creating modules and trying to make
>> solid communication between them. I have around 10 modules already.
>> But when I reached module 10, I realized that there's a mess in naming
>> events which modules throws to make communications:
>>
>> sandbox.events.say({
>> event: "drop icon",
>> data: {
>> "id": 3,
>> "coordinates": {
>> "x": 25,
>> "y": 69
>> }
>> }
>> })
>>
>> Therefore, I wished to ask to you if you have experience in naming
>> those events more properly? I would love to have semantic event names,
>> which could always get me a key (even I forgot what's this is event is
>> about), what does it really say. Do you think event names has to be
>> related to a module, which throws the event, or to modules, which are
>> going to read that event?!
>>
>> Would really appreciate your minds here…
>>
>> --
>> To view archived discussions from the original JSMentors Mailman list:
>> http://www.mail-archive.com/[email protected]/
>>
>> To search via a non-Google archive, visit here:
>> http://www.mail-archive.com/[email protected]/
>>
>> To unsubscribe from this group, send email to
>> [email protected]
>>
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]