Skip to content
This repository was archived by the owner on Aug 23, 2019. It is now read-only.
This repository was archived by the owner on Aug 23, 2019. It is now read-only.

Model#$on confusing #57

@colinmacdonald

Description

@colinmacdonald

Currently there are 5 events that can be listened for using model#on.

3 of these events are GoInstant key events, add, set, remove which can take an optionsObject and a listener:

model.$on('add', { local: true }, function() {})
model.$on('set', { bubble: true, listener: function() {} })
model.$on('remove', function() {})

The other 2 are ready and error which do not take an options object:

model.$on('ready', function() {})
model.$on('error', function(errObj) {})

These inconstancies could make the method confusing because how you call the method changes based on the eventName you passed.

  • With/without optsObj depending on the event being listened for
  • Listeners with different signatures depending on the event being listened for

Some alternative interface ideas:

Separate the key events from the local model events

model.$key.on // for 'add', 'set', 'remove' key events
model.$on // for model-only events ('ready', 'error')
// error and ready events given their only method that calls a listener
model.$error
model.$ready

// reserve model.$on for key events
model.$on('add', optsObj, listener);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions