Skip to content

Commit

Permalink
refactor(barn): useEmitter for Barn initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
nampdn committed Apr 24, 2019
1 parent ff64bbd commit ca6df1e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/barn/src/barn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const useBarnStream = (initialState: BarnState) => {

const onInitialized = emitter.addListener(BARN_INITIALIZE, () => {
state = initialState
emit(SET_BARN_STATE, state)
emit(SET_BARN_STATE, { path: '', state })
})

return () => {
Expand All @@ -58,11 +58,10 @@ export const useBarnStream = (initialState: BarnState) => {

// Emit initialize value to the barn's MemoryStream to making it able to use whenever new listener come.
setTimeout(() => {
barn$._$.shamefullySendNext({
eventType: SET_BARN_STATE({ name: BASICS_STREAM_ID }),
payload: { path: '', state: initialState },
streamName: BASICS_STREAM_ID,
})
const emit = useEmitter(BARN_INITIALIZE)
if (emit) {
emit()
}
})

return barn$
Expand Down

0 comments on commit ca6df1e

Please sign in to comment.