Example #1
0
 var rebuild = function () {
   href(function (link) {router(link)})
   if (entry.repo) {
     return actions.submitBuild(entry.repo)(dx)
   }
   if (entry.build) {
     return actions.submitBuild(entry.build.repository)(dx)
   }
 }
Example #2
0
    [INIT]: (_, sources) => {
      const effectActions = Pushable(function onClose (error) {
        // cleanup href and/or history
        console.error(error)
      })
      // enable catching <href a=""></href> links
      href(push)
      // enable HTML5 history API
      history(push)

      return effectActions

      function push (href) {
        effectActions.push({
          type: SET,
          payload: href
        })
      }
    },
Example #3
0
  function init () {
    const dispatch = sendAction({
      onaction: handleAction,
      onchange: handleChange,
      state: _state
    })

    href(function (location) {
      const newState = Object.assign({}, _state, { location })
      handleChange(undefined, newState, _state)
    })

    function handleAction (action, state) {
      const func = dotProp.get(_dataFlow, action.type)
      const [modelName, actionOrReducer, _func] = action.type.split('.')

      if (actionOrReducer === 'actions') {
        return func(action, state, dispatch)
      } else if (actionOrReducer === 'reducers') {
        const mutatedState = {}
        mutatedState[modelName] = func(action, state, dispatch)

        const newState = Object.assign({}, state, mutatedState)
        return newState
      }
    }

    function handleChange (action, state, prevState) {
      if (state === prevState) return

      const oldTree = document.getElementById('naka-root')
      const newTree = _router(state.location, state, dispatch)
      newTree.setAttribute('id', 'naka-root')
      yo.update(oldTree, newTree)
    }

    _state.location = window.location.pathname

    document
      .getElementById('naka-root')
      .appendChild(_router(window.location.pathname, _state, dispatch))
  }
Example #4
0
  run: (effect, sources) => {
    if (effect !== 'INIT_ROUTER') { return }
    const effectActions = Pushable(function onClose (error) {
      // cleanup href and/or history
      console.error(error)
    })
    // enable catching <href a=""></href> links
    href(push)
    // enable HTML5 history API
    history(push)

    return effectActions

    function push (href) {
      effectActions.push({
        type: 'SET_LOCATION',
        payload: href
      })
    }
  }
Example #5
0
const setLocationStream = () => {
  const routeActions = Pushable(function onClose (error) {
    // TODO: clean href and/or history
    debug('error: ', error)
  })

  function push (href) {
    debug('push - href: ', href)
    const pathname = parseUrl(href).pathname
    routeActions.push(setLocation({ href: href }))
    if (inputsMap[pathname]) {
      routeActions.push(inputLoaded({ inputId: inputsMap[pathname]}))
    }
  }

  href(push)
  history(push)

  debug('routeActions: ', routeActions)
  return routeActions
}
Example #6
0
 function onclick () {
   href(function (link) {router(link)})
 }
Example #7
0
 link.onclick = function () {
   href(function (link) {router(link)})
 }