mirror of
https://github.com/transloadit/uppy.git
synced 2026-01-23 02:25:07 +00:00
@uppy/store-redux: force new keyword
Refs: https://github.com/transloadit/uppy/pull/2949
This commit is contained in:
parent
e78722ec3a
commit
17f71da67f
4 changed files with 26 additions and 36 deletions
|
|
@ -77,10 +77,8 @@ function middleware () {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = function createReduxStore (opts) {
|
||||
return new ReduxStore(opts)
|
||||
}
|
||||
|
||||
module.exports = ReduxStore
|
||||
module.exports.ReduxStore = ReduxStore
|
||||
module.exports.STATE_UPDATE = STATE_UPDATE
|
||||
module.exports.reducer = reducer
|
||||
module.exports.middleware = middleware
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ describe('ReduxStore', () => {
|
|||
return Redux.createStore(reducer)
|
||||
}
|
||||
|
||||
it('can be created with or without new', () => {
|
||||
it('can be created with named or default import', () => {
|
||||
const r = createStore()
|
||||
let store = ReduxStore({ store: r })
|
||||
let store = new ReduxStore.ReduxStore({ store: r })
|
||||
expect(typeof store).toBe('object')
|
||||
store = new ReduxStore({ store: r })
|
||||
expect(typeof store).toBe('object')
|
||||
|
|
@ -17,7 +17,7 @@ describe('ReduxStore', () => {
|
|||
|
||||
it('merges in state using `setState`', () => {
|
||||
const r = createStore()
|
||||
const store = ReduxStore({ store: r })
|
||||
const store = new ReduxStore({ store: r })
|
||||
expect(store.getState()).toEqual({})
|
||||
|
||||
store.setState({
|
||||
|
|
@ -39,7 +39,7 @@ describe('ReduxStore', () => {
|
|||
}
|
||||
|
||||
const r = createStore()
|
||||
const store = ReduxStore({ store: r })
|
||||
const store = new ReduxStore({ store: r })
|
||||
store.subscribe(listener)
|
||||
|
||||
expected = [{}, { a: 1, b: 2 }, { a: 1, b: 2 }]
|
||||
|
|
@ -70,7 +70,7 @@ describe('ReduxStore', () => {
|
|||
expect([prevState, nextState, patch]).toEqual(expected)
|
||||
}
|
||||
|
||||
const store = ReduxStore({ store: r })
|
||||
const store = new ReduxStore({ store: r })
|
||||
store.subscribe(listener)
|
||||
|
||||
expected = [{}, { a: 1 }, { a: 1 }]
|
||||
|
|
@ -95,7 +95,7 @@ describe('ReduxStore', () => {
|
|||
hello: ReduxStore.reducer,
|
||||
})
|
||||
const r = Redux.createStore(reducer)
|
||||
const store = ReduxStore({
|
||||
const store = new ReduxStore({
|
||||
store: r,
|
||||
id: 'world',
|
||||
selector: state => state.hello.world,
|
||||
|
|
|
|||
34
packages/@uppy/store-redux/types/index.d.ts
vendored
34
packages/@uppy/store-redux/types/index.d.ts
vendored
|
|
@ -1,27 +1,21 @@
|
|||
import type { Store } from '@uppy/utils'
|
||||
import type { Reducer, Middleware, Store as Redux } from 'redux'
|
||||
|
||||
declare namespace ReduxStore {
|
||||
interface ReduxStoreOptions {
|
||||
store: Redux<object>
|
||||
id?: string
|
||||
selector?: (state: any) => object
|
||||
}
|
||||
|
||||
interface ReduxStore extends Store {
|
||||
constructor (opts: ReduxStoreOptions): ReduxStore
|
||||
getState (): object
|
||||
setState (patch: object): void
|
||||
subscribe (listener: any): () => void
|
||||
}
|
||||
|
||||
const reducer: Reducer<object>
|
||||
const middleware: Middleware
|
||||
const STATE_UPDATE: string
|
||||
interface ReduxStoreOptions {
|
||||
store: Redux<object>
|
||||
id?: string
|
||||
selector?: (state: any) => object
|
||||
}
|
||||
|
||||
declare function ReduxStore (
|
||||
opts: ReduxStore.ReduxStoreOptions
|
||||
): ReduxStore.ReduxStore
|
||||
export class ReduxStore implements Store {
|
||||
constructor (opts: ReduxStoreOptions)
|
||||
getState (): object
|
||||
setState (patch: object): void
|
||||
subscribe (listener: any): () => void
|
||||
}
|
||||
|
||||
export const reducer: Reducer<any>
|
||||
export const middleware: Middleware
|
||||
export const STATE_UPDATE: string
|
||||
|
||||
export default ReduxStore
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
import { createStore, combineReducers } from 'redux'
|
||||
import ReduxStore from '../'
|
||||
import ReduxStore, { reducer as uppy } from '..'
|
||||
|
||||
const reducer = combineReducers({
|
||||
uppy: ReduxStore.reducer
|
||||
})
|
||||
const reducer = combineReducers({ uppy })
|
||||
|
||||
const store = ReduxStore({
|
||||
store: createStore(reducer)
|
||||
const store = new ReduxStore({
|
||||
store: createStore(reducer),
|
||||
})
|
||||
|
||||
store.setState({ a: 1 })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue