bpetetot / conference-hall-beta

📣 An open SaaS platform to manage call for papers
https://conference-hall.io
MIT License
133 stars 46 forks source link

better management of data fetch when mounting / routing #135

Closed bpetetot closed 6 years ago

bpetetot commented 6 years ago

Discussion from PR #123

Find a way to manage data loading on routes and component mounting. Each time I have an URL with param eventId, I have to do a loader like that, I think I could factorize this code in a better way.

const mapStore = (store) => {
  const eventId = getRouterParam('eventId')(store.getState())
  const event = store.data.events.get(eventId)
  return {
    loaded: !!event,
    eventId,
    load: () => store.dispatch('@@ui/ON_LOAD_EVENT'),
  }
}
export default compose(
  forRoute.absolute('PROPOSALS'),
  inject(mapStore),
  loader,
)(Proposals)

Idea from @fabienjuif : Look at the new hoc listen. Maybe we can dispatch an event in this hoc like @@krml/LISTEN_PLUGUED>${componentName} And in the listeners you plug with listen hoc, you catch that ?

fabienjuif commented 6 years ago

This LISTEN event is already present into k-ramel

container

import listeners from './proposals.listeners'

export default listen(listeners, 'proposals')(Proposals)

listeners

import { when, reaction } from 'k-ramel'

export default [
    when('@@krml/LISTENERS>ADDED>proposals')(reaction((action, store) => {
      console.log('yo')
    })),
]
bpetetot commented 6 years ago

Yes I know ;) this issue is here just to do it.

bpetetot commented 6 years ago

Done for proposals in PR #284 must be done over other app's parts in a bigger refactoring