createFilesBundle = () => {
  return {
    name: 'files',

    /**
     * @param {Model} state
     * @param {Message} action
     * @returns {Model}
     */
    reducer: (state = DEFAULT_STATE, action) => {
      switch (action.type) {
        case ACTIONS.DELETE:
        case ACTIONS.ADD_BY_PATH:
        case ACTIONS.DOWNLOAD_LINK:
        case ACTIONS.SHARE_LINK:
        case ACTIONS.MOVE:
        case ACTIONS.COPY:
        case ACTIONS.MAKE_DIR:
        case ACTIONS.PIN_ADD:
        case ACTIONS.PIN_REMOVE:
          return updateJob(state, action.task, action.type)
        case ACTIONS.WRITE: {
          return updateJob(state, action.task, action.type)
        }
        case ACTIONS.PIN_LIST: {
          const { task, type } = action

          const pins = task.status === 'Exit' && task.result.ok
            ? task.result.value.pins.map(String)
            : state.pins

          return {
            ...updateJob(state, task, type),
            pins
          }
        }
        case ACTIONS.FETCH: {
          const { task, type } = action
          const result = task.status === 'Exit' && task.result.ok
            ? task.result.value
            : null
          const { pageContent } = result
            ? {
                pageContent: result
              }
            : state

          return {
            ...updateJob(state, task, type),
            pageContent
          }
        }
        case ACTIONS.DISMISS_ERRORS: {
          return {
            ...state,
            failed: []
          }
        }
        case ACTIONS.CLEAR_ALL: {
          return {
            ...state,
            failed: [],
            finished: [],
            pending: []
          }
        }
        case ACTIONS.UPDATE_SORT: {
          const { pageContent } = state
          if (pageContent && pageContent.type === 'directory') {
            const content = sortFiles(pageContent.content, action.payload)
            return {
              ...state,
              pageContent: {
                ...pageContent,
                content
              },
              sorting: action.payload
            }
          } else {
            return state
          }
        }
        case ACTIONS.SIZE_GET: {
          const { task, type } = action
          const mfsSize = task.status === 'Exit' && task.result.ok
            ? task.result.value.size
            : state.mfsSize

          return {
            ...updateJob(state, task, type),
            mfsSize
          }
        }
        default: {
          return state
        }
      }
    },
    ...actions(),
    ...selectors()
  }
}
@typedef {import('./protocol').Model} Model
@typedef {import('./protocol').Message} Message
@typedef {import('../task').SpawnState<any, Error, any, any>} JobState