Browse Source

Merge pull request #667 from transloadit/chore/remove-redux-plugin

Remove Redux state sync plugin
Artur Paikin 7 years ago
parent
commit
d92b673001
3 changed files with 1 additions and 169 deletions
  1. 1 3
      src/index.js
  2. 0 33
      src/plugins/Redux.js
  3. 0 133
      src/plugins/Redux.test.js

+ 1 - 3
src/index.js

@@ -29,7 +29,6 @@ const Form = require('./plugins/Form')
 const ThumbnailGenerator = require('./plugins/ThumbnailGenerator')
 const ThumbnailGenerator = require('./plugins/ThumbnailGenerator')
 const GoldenRetriever = require('./plugins/GoldenRetriever')
 const GoldenRetriever = require('./plugins/GoldenRetriever')
 const ReduxDevTools = require('./plugins/ReduxDevTools')
 const ReduxDevTools = require('./plugins/ReduxDevTools')
-const ReduxStore = require('./plugins/Redux')
 
 
 module.exports = {
 module.exports = {
   Core,
   Core,
@@ -52,6 +51,5 @@ module.exports = {
   Form,
   Form,
   ThumbnailGenerator,
   ThumbnailGenerator,
   GoldenRetriever,
   GoldenRetriever,
-  ReduxDevTools,
-  ReduxStore
+  ReduxDevTools
 }
 }

+ 0 - 33
src/plugins/Redux.js

@@ -1,33 +0,0 @@
-const Plugin = require('../core/Plugin')
-
-module.exports = class Redux extends Plugin {
-  constructor (uppy, opts) {
-    super(uppy, opts)
-    this.type = 'state-sync'
-    this.id = 'Redux'
-    this.title = 'Redux Emitter'
-
-    if (typeof opts.action === 'undefined') {
-      throw new Error('action option is not defined')
-    }
-    if (typeof opts.dispatch === 'undefined') {
-      throw new Error('dispatch option is not defined')
-    }
-    this.opts = opts
-
-    this.handleStateUpdate = this.handleStateUpdate.bind(this)
-  }
-
-  handleStateUpdate (prev, state, patch) {
-    this.opts.dispatch(this.opts.action(prev, state, patch)) // this dispatches a redux event with the new state
-  }
-
-  install () {
-    this.uppy.on('state-update', this.handleStateUpdate)
-    this.handleStateUpdate({}, this.uppy.state, this.uppy.state) // set the initial redux state
-  }
-
-  uninstall () {
-    this.uppy.off('state-update', this.handleStateUpdate)
-  }
-}

+ 0 - 133
src/plugins/Redux.test.js

@@ -1,133 +0,0 @@
-import ReduxPlugin from './Redux'
-import Plugin from '../core/Plugin'
-
-describe('uploader/reduxPlugin', () => {
-  it('should initialise successfully', () => {
-    const actionFunction = () => {}
-    const dispatchFunction = () => {}
-    const redux = new ReduxPlugin(null, {
-      action: actionFunction,
-      dispatch: dispatchFunction
-    })
-    expect(redux instanceof Plugin).toEqual(true)
-    expect(redux.opts.action).toBe(actionFunction)
-    expect(redux.opts.dispatch).toBe(dispatchFunction)
-  })
-
-  it('should throw an error if the action option is not specified', () => {
-    const dispatchFunction = () => {}
-
-    expect(() => {
-      new ReduxPlugin(null, { dispatch: dispatchFunction }) // eslint-disable-line no-new
-    }).toThrow('action option is not defined')
-  })
-
-  it('should throw an error if the dispatch option is not specified', () => {
-    const actionFunction = () => {}
-
-    expect(() => {
-      new ReduxPlugin(null, { action: actionFunction }) // eslint-disable-line no-new
-    }).toThrow('dispatch option is not defined')
-  })
-
-  describe('install', () => {
-    it('should subscribe to uppy events', () => {
-      const core = {
-        on: jest.fn()
-      }
-
-      const redux = new ReduxPlugin(core, {
-        action: () => {},
-        dispatch: () => {}
-      })
-      redux.handleStateUpdate = jest.fn()
-      redux.install()
-
-      expect(core.on.mock.calls.length).toEqual(1)
-      expect(core.on.mock.calls[0]).toEqual([
-        'state-update',
-        redux.handleStateUpdate
-      ])
-    })
-
-    it('should call this.handleStateUpdate with the current state on install', () => {
-      const core = {
-        on: jest.fn()
-      }
-
-      const redux = new ReduxPlugin(core, {
-        action: () => {},
-        dispatch: () => {}
-      })
-      redux.handleStateUpdate = jest.fn()
-      redux.install()
-
-      expect(redux.handleStateUpdate.mock.calls.length).toEqual(1)
-      expect(redux.handleStateUpdate.mock.calls[0]).toEqual([
-        {},
-        core.state,
-        core.state
-      ])
-    })
-  })
-
-  describe('uninstall', () => {
-    it('should should unsubscribe from uppy events on uninstall', () => {
-      const core = {
-        off: jest.fn()
-      }
-
-      const redux = new ReduxPlugin(core, {
-        action: () => {},
-        dispatch: () => {}
-      })
-      redux.uninstall()
-
-      expect(core.off.mock.calls.length).toEqual(1)
-      expect(core.off.mock.calls[0]).toEqual([
-        'state-update',
-        redux.handleStateUpdate
-      ])
-    })
-  })
-
-  describe('handleStateUpdate', () => {
-    it('should create a redux action with the new state', () => {
-      const core = {}
-      const actionMock = jest.fn().mockReturnValue({
-        foo: 'bar'
-      })
-      const dispatchMock = () => {}
-
-      const redux = new ReduxPlugin(core, {
-        action: actionMock,
-        dispatch: dispatchMock
-      })
-      const prev = { a: 'b' }
-      const state = { a: 'b', c: 'd' }
-      const patch = { c: 'd' }
-      redux.handleStateUpdate(prev, state, patch)
-      expect(actionMock.mock.calls.length).toEqual(1)
-      expect(actionMock.mock.calls[0]).toEqual([prev, state, patch])
-    })
-
-    it('should dispatch a redux action with the new state', () => {
-      const core = {}
-      const actionMock = jest.fn().mockReturnValue({
-        foo: 'bar'
-      })
-      const dispatchMock = jest.fn()
-
-      const redux = new ReduxPlugin(core, {
-        action: actionMock,
-        dispatch: dispatchMock
-      })
-      const prev = { a: 'b' }
-      const state = { a: 'b', c: 'd' }
-      const patch = { c: 'd' }
-      redux.handleStateUpdate(prev, state, patch)
-      expect(dispatchMock.mock.calls.length).toEqual(1)
-      expect(dispatchMock.mock.calls[0]).toEqual([{ foo: 'bar' }])
-    })
-  })
-})