Skip to content

Instantly share code, notes, and snippets.

@rpominov
Last active May 4, 2016 22:34
Show Gist options
  • Save rpominov/acb11abfb5383be6db70 to your computer and use it in GitHub Desktop.
Save rpominov/acb11abfb5383be6db70 to your computer and use it in GitHub Desktop.
Router concept
// trnsitionRequests -> BrowserAPI -> [ resolveRoute -> loadData -> render -> restoreScroll ]

// poor man's strem.flatMapLatest()
router.pipe((payload, next) => {
  next(1)
  next(2)
  return () => {
    // cleanup
  }
})

createRouter(callback => {
  browserHistoryAPI.listen(callback)
})
.pipe(createNestedReactResolver(...))
.pipe(createReactDataLoader(...))
.pipe(createNestedReactRenderer(...))
.pipe(createScrollRestorer(...))
@rpominov
Copy link
Author

@rpominov
Copy link
Author

Possible parts

@rpominov
Copy link
Author

rpominov commented May 4, 2016

  1. source → flatMapLatest → flatMapLatest → flatMapLatest → handler
  2. Event = Normal | Error | Redirect | End
  3. fmlNormal, fmlError, fmlRedirect, fmlEnd (?)
  4. on server source emits a Normal and an End, then we wait for End on other side and use the previous Event
  5. fml(a -> Stream<b,c,d> | Event<b,c,d>)

@rpominov
Copy link
Author

rpominov commented May 4, 2016

Event = {type: ... | 'END', payload: any}
Middleware = Event -> Event | Stream<Event> | Array<Event>

{type: 'END'} is special Event, we automatically dispose subscription after it. Other types like 'NORMAL', 'ERROR', 'REDIRECT', etc. are up to user (or maybe not, we might need a convention for example if we provide middlewares out of the box, but only END is special anyway)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment