yoshuawuyts / barracks

:mountain_railway: action dispatcher for unidirectional data flows

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expose `createSend` on the store object?

anandthakker opened this issue · comments

@yoshuawuyts What do you think about exposing createSend on the store object upon the first call to start? (Before the first call, it could be either undefined or a placeholder function that just throws an error.)

commented

@anandthakker what's the use case?

I'm working on a router-less setup where I need to mount multiple views to different elements on the page. I thought I'd use a model to track the element-view mapping, and possibly other lifecycle-related state that we end up needing down the road. So, my mount-view module currently looks something like:

const store = require('./store')

store.model({ /* ... set up the model for tracking the state of the element-to-view mapping ... */)

module.exports = function (send) {
  return function mountView (...) {
    /* do some stuff */
    send('views:mount', {...})
  }
}

You can see here that there's a bit of dependency injection happening: currently I wait until after doing store.start() to create the mountView function using a created send function. However, I need to export mountView to the folks using our code, so I'd really prefer to have it look something like:

const store = require('./store')

store.model({ /* ... set up the model for tracking the state of the element-to-view mapping ... */)

var send
module.exports = function mountView (...) {
  if (!send) { send = store.createSend('mount-view', true) }
  /* do some stuff */
  send('views:mount', {...})
}

OR, maybe even better, if the store had a default send function attached, I wouldn't even need to createSend...

Definitely in early stages of thinking through the architecture here, so I'm definitely open to push back on this :)

commented

@anandthakker I believe we talked about this on Slack - is it still an issue? Any way I can assist?

Ah yeah -- no longer an issue, I think. Closing.