diff --git a/browser/src/Editor/NeovimEditor/NeovimEditorStore.ts b/browser/src/Editor/NeovimEditor/NeovimEditorStore.ts index 6ec4827068..b842833fb7 100644 --- a/browser/src/Editor/NeovimEditor/NeovimEditorStore.ts +++ b/browser/src/Editor/NeovimEditor/NeovimEditorStore.ts @@ -6,16 +6,16 @@ import * as types from "vscode-languageserver-types" -import * as Oni from "oni-api" import { Store } from "redux" import thunk from "redux-thunk" +import * as Oni from "oni-api" +import { createStore as createReduxStore } from "oni-core-redux" + import { IConfigurationValues } from "./../../Services/Configuration" import { DefaultThemeColors, IThemeColors } from "./../../Services/Themes" -import { createStore as createReduxStore } from "./../../Redux" - import { IBufferLayer } from "./../NeovimEditor/BufferLayerManager" export interface Layers { diff --git a/browser/src/Redux/LoggingMiddleware.ts b/browser/src/Redux/LoggingMiddleware.ts deleted file mode 100644 index 60ccd0d974..0000000000 --- a/browser/src/Redux/LoggingMiddleware.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * LoggingMiddleware - * - * Logging strategy for Redux, specific to Oni - */ - -import { Store } from "redux" - -import * as Log from "./../Log" - -export const createLoggingMiddleware = (storeName: string) => (store: Store) => ( - next: any, -) => (action: any): any => { - Log.verbose("[REDUX - " + storeName + "][ACTION] " + action.type) - - const result = next(action) - - return result -} diff --git a/browser/src/Redux/RequestAnimationFrameNotifyBatcher.ts b/browser/src/Redux/RequestAnimationFrameNotifyBatcher.ts deleted file mode 100644 index 5766be4dd4..0000000000 --- a/browser/src/Redux/RequestAnimationFrameNotifyBatcher.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * RAFNotifyBatcher - * - * Helper method to 'batch' dispatches to redux store - * subscriptions, based on animation frames. - * - * This helps 'debounce' the rendering logic - - * otherwise we'd be re-rendering the UI every time - * an action is dispatched. - */ - -import { NotifyFunction } from "redux-batched-subscribe" - -export const RequestAnimationFrameNotifyBatcher = () => { - let rafId: number = null - - return (notify: NotifyFunction) => { - if (rafId) { - return - } - - rafId = window.requestAnimationFrame(() => { - rafId = null - notify() - }) - } -} diff --git a/browser/src/Redux/createStore.ts b/browser/src/Redux/createStore.ts deleted file mode 100644 index cc3797238e..0000000000 --- a/browser/src/Redux/createStore.ts +++ /dev/null @@ -1,46 +0,0 @@ -/* - * createStore - * - * Common utilities for creating a redux store with Oni - * - * Implementations some common functionality, like: - * - Logging - * - Throttled subscriptions - */ - -import { - applyMiddleware, - compose, - createStore as reduxCreateStore, - Middleware, - Reducer, - Store, -} from "redux" -import { batchedSubscribe } from "redux-batched-subscribe" - -import { createLoggingMiddleware } from "./LoggingMiddleware" - -import { RequestAnimationFrameNotifyBatcher } from "./RequestAnimationFrameNotifyBatcher" - -export const createStore = ( - name: string, - reducer: Reducer, - defaultState: TState, - optionalMiddleware: Middleware[] = [], -): Store => { - // tslint:disable-next-line no-string-literal - const composeFunction: any = window["__REDUX_DEVTOOLS_EXTENSION_COMPOSE__"] - - const composeEnhancers = - typeof window === "object" && composeFunction ? composeFunction({ name }) : compose // tslint:disable-line no-string-literal - - const loggingMiddleware: Middleware = createLoggingMiddleware(name) - - const middleware = [loggingMiddleware, ...optionalMiddleware] - - const enhancer = composeEnhancers( - applyMiddleware(...middleware), - batchedSubscribe(RequestAnimationFrameNotifyBatcher()), - ) - return reduxCreateStore(reducer, defaultState, enhancer) -} diff --git a/browser/src/Redux/index.ts b/browser/src/Redux/index.ts deleted file mode 100644 index c86f9183c0..0000000000 --- a/browser/src/Redux/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./createStore" diff --git a/browser/src/Services/Completion/CompletionStore.ts b/browser/src/Services/Completion/CompletionStore.ts index 69dead1962..83b79c3e73 100644 --- a/browser/src/Services/Completion/CompletionStore.ts +++ b/browser/src/Services/Completion/CompletionStore.ts @@ -5,6 +5,7 @@ import * as types from "vscode-languageserver-types" import * as Oni from "oni-api" +import { createStore as oniCreateStore } from "oni-core-redux" import "rxjs/add/operator/mergeMap" import { Observable } from "rxjs/Observable" @@ -12,8 +13,6 @@ import { Observable } from "rxjs/Observable" import { combineReducers, Reducer, Store } from "redux" import { combineEpics, createEpicMiddleware, Epic } from "redux-observable" -import { createStore as oniCreateStore } from "./../../Redux" - import { Configuration } from "./../Configuration" import { LanguageManager } from "./../Language" import { SnippetManager } from "./../Snippets" diff --git a/browser/src/Services/ContextMenu/ContextMenu.tsx b/browser/src/Services/ContextMenu/ContextMenu.tsx index c20af9e783..a621ab9896 100644 --- a/browser/src/Services/ContextMenu/ContextMenu.tsx +++ b/browser/src/Services/ContextMenu/ContextMenu.tsx @@ -11,10 +11,10 @@ import thunk from "redux-thunk" import * as types from "vscode-languageserver-types" import * as Oni from "oni-api" +import { createStore } from "oni-core-redux" import { Event, IEvent } from "oni-types" import { IToolTipsProvider } from "./../../Editor/NeovimEditor/ToolTipsProvider" -import { createStore } from "./../../Redux" import { IColors } from "./../../Services/Colors" import * as ActionCreators from "./../Menu/MenuActionCreators" diff --git a/browser/src/Services/Explorer/ExplorerStore.ts b/browser/src/Services/Explorer/ExplorerStore.ts index e522b86792..6ea86078de 100644 --- a/browser/src/Services/Explorer/ExplorerStore.ts +++ b/browser/src/Services/Explorer/ExplorerStore.ts @@ -16,8 +16,9 @@ import { forkJoin } from "rxjs/observable/forkJoin" import { fromPromise } from "rxjs/observable/fromPromise" import { timer } from "rxjs/observable/timer" +import { createStore as createReduxStore } from "oni-core-redux" + import * as Log from "./../../Log" -import { createStore as createReduxStore } from "./../../Redux" import { configuration } from "./../Configuration" import { EmptyNode, ExplorerNode } from "./ExplorerSelectors" @@ -801,7 +802,9 @@ const persistOrDeleteNode = async ( export const undoEpic: ExplorerEpic = (action$, store, { fileSystem }) => action$.ofType("UNDO").mergeMap(action => { - const { register: { undo } } = store.getState() + const { + register: { undo }, + } = store.getState() const lastAction = last(undo) switch (lastAction.type) { @@ -919,7 +922,11 @@ const expandDirectoryEpic: ExplorerEpic = (action$, store, { fileSystem }) => export const createNodeEpic: ExplorerEpic = (action$, store, { fileSystem }) => action$.ofType("CREATE_NODE_COMMIT").mergeMap(({ name }: ICreateNodeCommitAction) => { - const { register: { create: { nodeType } } } = store.getState() + const { + register: { + create: { nodeType }, + }, + } = store.getState() const shouldExpand = Actions.expandDirectory(path.dirname(name)) const createFileOrFolder = nodeType === "file" ? fileSystem.writeFile(name) : fileSystem.mkdir(name) diff --git a/browser/src/Services/KeyDisplayer/KeyDisplayerStore.ts b/browser/src/Services/KeyDisplayer/KeyDisplayerStore.ts index 71b4790db9..27329e9f74 100644 --- a/browser/src/Services/KeyDisplayer/KeyDisplayerStore.ts +++ b/browser/src/Services/KeyDisplayer/KeyDisplayerStore.ts @@ -4,8 +4,8 @@ * State management for the KeyDisplayer */ +import { createStore as createReduxStore } from "oni-core-redux" import { Reducer, Store } from "redux" -import { createStore as createReduxStore } from "./../../Redux" import { createEpicMiddleware, Epic } from "redux-observable" import "rxjs/add/operator/delay" diff --git a/browser/src/Services/Language/LanguageStore.ts b/browser/src/Services/Language/LanguageStore.ts index 93896a9f66..00389efc99 100644 --- a/browser/src/Services/Language/LanguageStore.ts +++ b/browser/src/Services/Language/LanguageStore.ts @@ -11,7 +11,7 @@ import { Observable } from "rxjs/Observable" import { combineReducers, Reducer, Store } from "redux" import { combineEpics, createEpicMiddleware, Epic } from "redux-observable" -import { createStore as oniCreateStore } from "./../../Redux" +import { createStore as oniCreateStore } from "oni-core-redux" import { Configuration } from "./../Configuration" diff --git a/browser/src/Services/Menu/Menu.ts b/browser/src/Services/Menu/Menu.ts index 633da42c0e..bfe6327790 100644 --- a/browser/src/Services/Menu/Menu.ts +++ b/browser/src/Services/Menu/Menu.ts @@ -8,6 +8,7 @@ import { bindActionCreators } from "redux" import thunk from "redux-thunk" import * as Oni from "oni-api" +import { createStore } from "oni-core-redux" import { Event, IEvent } from "oni-types" import * as ActionCreators from "./MenuActionCreators" @@ -20,8 +21,6 @@ import { MenuContainer } from "./MenuComponent" import { Configuration } from "./../Configuration" import { Overlay, OverlayManager } from "./../Overlay" -import { createStore } from "./../../Redux" - export interface IMenuOptionWithHighlights extends Oni.Menu.MenuOption { labelHighlights: number[] detailHighlights: number[] diff --git a/browser/src/Services/Notifications/NotificationStore.ts b/browser/src/Services/Notifications/NotificationStore.ts index 01264045f6..17c9b9d3ad 100644 --- a/browser/src/Services/Notifications/NotificationStore.ts +++ b/browser/src/Services/Notifications/NotificationStore.ts @@ -4,10 +4,10 @@ * State management for Notifications */ +import { createStore as createReduxStore } from "oni-core-redux" import { Reducer, Store } from "redux" import { combineEpics, createEpicMiddleware, Epic } from "redux-observable" import { Observable } from "rxjs" -import { createStore as createReduxStore } from "./../../Redux" export type NotificationLevel = "info" | "warn" | "error" | "success" diff --git a/browser/src/Services/Sidebar/SidebarStore.ts b/browser/src/Services/Sidebar/SidebarStore.ts index 43931a8e95..f226d86593 100644 --- a/browser/src/Services/Sidebar/SidebarStore.ts +++ b/browser/src/Services/Sidebar/SidebarStore.ts @@ -4,8 +4,8 @@ * State management for the sidebar split */ +import { createStore as createReduxStore } from "oni-core-redux" import { Reducer, Store } from "redux" -import { createStore as createReduxStore } from "./../../Redux" import { configuration } from "../Configuration" import { WindowManager, WindowSplitHandle } from "./../WindowManager" diff --git a/browser/src/Services/Sneak/SneakStore.ts b/browser/src/Services/Sneak/SneakStore.ts index beea70b835..9bf77b29b6 100644 --- a/browser/src/Services/Sneak/SneakStore.ts +++ b/browser/src/Services/Sneak/SneakStore.ts @@ -7,8 +7,7 @@ import { Reducer, Store } from "redux" import { Shapes } from "oni-api" - -import { createStore as createReduxStore } from "./../../Redux" +import { createStore as createReduxStore } from "oni-core-redux" export interface ISneakInfo { rectangle: Shapes.Rectangle diff --git a/browser/src/Services/SyntaxHighlighting/SyntaxHighlightingStore.ts b/browser/src/Services/SyntaxHighlighting/SyntaxHighlightingStore.ts index 7eba48f44a..166b2f4b68 100644 --- a/browser/src/Services/SyntaxHighlighting/SyntaxHighlightingStore.ts +++ b/browser/src/Services/SyntaxHighlighting/SyntaxHighlightingStore.ts @@ -8,9 +8,10 @@ import { Store } from "redux" import * as types from "vscode-languageserver-types" import { StackElement } from "vscode-textmate" +import { createStore } from "oni-core-redux" + import * as Log from "./../../Log" import * as PeriodicJobs from "./../../PeriodicJobs" -import { createStore } from "./../../Redux" import { configuration } from "./../Configuration" import { GrammarLoader } from "./GrammarLoader" diff --git a/browser/src/Services/WindowManager/WindowManagerStore.ts b/browser/src/Services/WindowManager/WindowManagerStore.ts index f4cd0b010e..4dc3753eee 100644 --- a/browser/src/Services/WindowManager/WindowManagerStore.ts +++ b/browser/src/Services/WindowManager/WindowManagerStore.ts @@ -6,8 +6,8 @@ import * as Oni from "oni-api" +import { createStore as createReduxStore } from "oni-core-redux" import { Reducer, Store } from "redux" -import { createStore as createReduxStore } from "./../../Redux" import { Direction, ISplitInfo, SplitDirection } from "./index" diff --git a/browser/src/UI/Shell/Shell.tsx b/browser/src/UI/Shell/Shell.tsx index 3b02bdac95..5b7445010f 100644 --- a/browser/src/UI/Shell/Shell.tsx +++ b/browser/src/UI/Shell/Shell.tsx @@ -14,6 +14,8 @@ import { remote } from "electron" import { bindActionCreators } from "redux" import thunk from "redux-thunk" +import { createStore } from "oni-core-redux" + import { ShellView } from "./ShellView" import * as ActionCreators from "./ShellActionCreators" @@ -24,8 +26,6 @@ import { Colors } from "./../../Services/Colors" import { focusManager } from "./../../Services/FocusManager" import { windowManager } from "./../../Services/WindowManager" -import { createStore } from "./../../Redux" - const defaultState = State.createDefaultState() export const store = createStore("Shell", reducer, defaultState, [thunk]) diff --git a/package.json b/package.json index 3518483696..eafd19a333 100644 --- a/package.json +++ b/package.json @@ -958,6 +958,7 @@ "mocha": "3.1.2", "node-abi": "^2.4.1", "nyc": "^11.4.1", + "oni-core-redux": "^1.0.0", "oni-release-downloader": "^0.0.10", "opencollective": "1.0.3", "prettier": "^1.12.1", diff --git a/yarn.lock b/yarn.lock index 3f77e84f6d..db98892633 100644 --- a/yarn.lock +++ b/yarn.lock @@ -245,6 +245,12 @@ dependencies: redux "^3.6.0" +"@types/redux@^3.6.0": + version "3.6.0" + resolved "https://registry.yarnpkg.com/@types/redux/-/redux-3.6.0.tgz#f1ebe1e5411518072e4fdfca5c76e16e74c1399a" + dependencies: + redux "*" + "@types/rimraf@^2.0.2": version "2.0.2" resolved "https://registry.yarnpkg.com/@types/rimraf/-/rimraf-2.0.2.tgz#7f0fc3cf0ff0ad2a99bb723ae1764f30acaf8b6e" @@ -7337,6 +7343,19 @@ oni-api@^0.0.45: version "0.0.45" resolved "https://registry.yarnpkg.com/oni-api/-/oni-api-0.0.45.tgz#e9191fbc5069e01b3cbea644bc697be9aaf1d699" +oni-core-logging@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/oni-core-logging/-/oni-core-logging-1.0.0.tgz#7ad6c0ad8b06c23255202f97e229c2b0947dcf0b" + +oni-core-redux@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/oni-core-redux/-/oni-core-redux-1.0.0.tgz#07bc9650b256afda857d049cd1994bf3542fe475" + dependencies: + "@types/redux" "^3.6.0" + oni-core-logging "^1.0.0" + redux "^4.0.0" + redux-batched-subscribe "^0.1.6" + oni-neovim-binaries@0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/oni-neovim-binaries/-/oni-neovim-binaries-0.1.1.tgz#7aed74c14bca2581e1447c557541192dd5e89cdd" @@ -8570,6 +8589,13 @@ redux-thunk@2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.2.0.tgz#e615a16e16b47a19a515766133d1e3e99b7852e5" +redux@*, redux@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.0.tgz#aa698a92b729315d22b34a0553d7e6533555cc03" + dependencies: + loose-envify "^1.1.0" + symbol-observable "^1.2.0" + redux@3.7.2, redux@>=1.0.0, redux@^3.6.0, redux@^3.7.1: version "3.7.2" resolved "https://registry.yarnpkg.com/redux/-/redux-3.7.2.tgz#06b73123215901d25d065be342eb026bc1c8537b" @@ -9788,6 +9814,10 @@ symbol-observable@^1.0.3: version "1.0.4" resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.0.4.tgz#29bf615d4aa7121bdd898b22d4b3f9bc4e2aa03d" +symbol-observable@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804" + symbol-tree@^3.2.1, symbol-tree@^3.2.2: version "3.2.2" resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.2.tgz#ae27db38f660a7ae2e1c3b7d1bc290819b8519e6"