Skip to content
This repository has been archived by the owner on Jul 11, 2019. It is now read-only.

Avoid passing app to UI elements #16

Closed
shama opened this issue Apr 27, 2015 · 3 comments
Closed

Avoid passing app to UI elements #16

shama opened this issue Apr 27, 2015 · 3 comments

Comments

@shama
Copy link
Member

shama commented Apr 27, 2015

Currently we are passing app into the UI elements to send events up. But this will create peer dependencies to app and make it harder to split out the UI elements into their own modules.

Instead we should just create a target callback for sending actions up. Such as:

function action (name, params) {
  /* Handle action name */
}
self.views = {
    channels: new Channels({ target: action })
}

and then in the UI element:

function Composer (opts) {
  opts = opts || {}
  this.target = opts.target || function() {}
}

Composer.prototype.render = function () {
  var self = this

  var input = h('input', {
    placeholder: 'Send a message...',
    autofocus: true
  })

  return h('form.composer', {
    onsubmit: function (e) {
      e.preventDefault()
      var input = this.querySelector('input')
      self.target('sendMessage', input.value)
      input.value = ''
    }
  }, input)
}

Or get more fancy and have the actions bubble up: https://gist.github.com/shama/33f7aaeb902a001637e8

@ungoldman
Copy link
Member

what about each component being an event emitter and app just instantiating them and managing event passing/delegation

@shama
Copy link
Member Author

shama commented Apr 27, 2015

Yep that would be cool too. Just anything that can pass actions up that isn't another library passed into the constructor. :)

@shama
Copy link
Member Author

shama commented Apr 27, 2015

Trying out an event emitter approach: 585e155

@shama shama closed this as completed in d20b364 Apr 28, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants