From 37425e7ae80391f4c9dfb55e13a777700ffc9c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=BCchele?= Date: Tue, 31 Jul 2018 07:37:19 -0700 Subject: [PATCH] persist state over reload Summary: The selected device, app and plugin are not persisted over a reload using `redux-persist`. Reviewed By: jknoxville Differential Revision: D8836481 fbshipit-source-id: 3ace1a950a200255d5daf77791d706ede0ff2138 --- .../redux-persist-transform-filter_vx.x.x.js | 38 ++ flow-typed/npm/redux-persist_vx.x.x.js | 480 ++++++++++++++++++ package.json | 2 + src/init.js | 23 +- yarn.lock | 44 ++ 5 files changed, 586 insertions(+), 1 deletion(-) create mode 100644 flow-typed/npm/redux-persist-transform-filter_vx.x.x.js create mode 100644 flow-typed/npm/redux-persist_vx.x.x.js diff --git a/flow-typed/npm/redux-persist-transform-filter_vx.x.x.js b/flow-typed/npm/redux-persist-transform-filter_vx.x.x.js new file mode 100644 index 000000000..aa5e955db --- /dev/null +++ b/flow-typed/npm/redux-persist-transform-filter_vx.x.x.js @@ -0,0 +1,38 @@ +// flow-typed signature: bceb6369b73edaf417e6a8dadec84e4d +// flow-typed version: <>/redux-persist-transform-filter_v0.0.18/flow_v0.76.0 + +/** + * This is an autogenerated libdef stub for: + * + * 'redux-persist-transform-filter' + * + * Fill this stub out by replacing all the `any` types. + * + * Once filled out, we encourage you to share your work with the + * community by sending a pull request to: + * https://github.com/flowtype/flow-typed + */ + +declare module 'redux-persist-transform-filter' { + declare module.exports: any; +} + +/** + * We include stubs for each file inside this npm package in case you need to + * require those files directly. Feel free to delete any files that aren't + * needed. + */ +declare module 'redux-persist-transform-filter/dist/index' { + declare module.exports: any; +} + +// Filename aliases +declare module 'redux-persist-transform-filter/dist/index.js' { + declare module.exports: $Exports<'redux-persist-transform-filter/dist/index'>; +} +declare module 'redux-persist-transform-filter/index' { + declare module.exports: $Exports<'redux-persist-transform-filter'>; +} +declare module 'redux-persist-transform-filter/index.js' { + declare module.exports: $Exports<'redux-persist-transform-filter'>; +} diff --git a/flow-typed/npm/redux-persist_vx.x.x.js b/flow-typed/npm/redux-persist_vx.x.x.js new file mode 100644 index 000000000..50c9f8def --- /dev/null +++ b/flow-typed/npm/redux-persist_vx.x.x.js @@ -0,0 +1,480 @@ +// flow-typed signature: ac14c5c7c3e8767ae819a78c6cd4f19d +// flow-typed version: <>/redux-persist_v5.10.0/flow_v0.76.0 + +/** + * This is an autogenerated libdef stub for: + * + * 'redux-persist' + * + * Fill this stub out by replacing all the `any` types. + * + * Once filled out, we encourage you to share your work with the + * community by sending a pull request to: + * https://github.com/flowtype/flow-typed + */ + +declare module 'redux-persist' { + declare module.exports: any; +} + +/** + * We include stubs for each file inside this npm package in case you need to + * require those files directly. Feel free to delete any files that aren't + * needed. + */ +declare module 'redux-persist/dist/redux-persist' { + declare module.exports: any; +} + +declare module 'redux-persist/dist/redux-persist.min' { + declare module.exports: any; +} + +declare module 'redux-persist/es/constants' { + declare module.exports: any; +} + +declare module 'redux-persist/es/createMigrate' { + declare module.exports: any; +} + +declare module 'redux-persist/es/createPersistoid' { + declare module.exports: any; +} + +declare module 'redux-persist/es/createTransform' { + declare module.exports: any; +} + +declare module 'redux-persist/es/getStoredState' { + declare module.exports: any; +} + +declare module 'redux-persist/es/index' { + declare module.exports: any; +} + +declare module 'redux-persist/es/integration/getStoredStateMigrateV4' { + declare module.exports: any; +} + +declare module 'redux-persist/es/integration/react' { + declare module.exports: any; +} + +declare module 'redux-persist/es/persistCombineReducers' { + declare module.exports: any; +} + +declare module 'redux-persist/es/persistReducer' { + declare module.exports: any; +} + +declare module 'redux-persist/es/persistStore' { + declare module.exports: any; +} + +declare module 'redux-persist/es/purgeStoredState' { + declare module.exports: any; +} + +declare module 'redux-persist/es/stateReconciler/autoMergeLevel1' { + declare module.exports: any; +} + +declare module 'redux-persist/es/stateReconciler/autoMergeLevel2' { + declare module.exports: any; +} + +declare module 'redux-persist/es/stateReconciler/hardSet' { + declare module.exports: any; +} + +declare module 'redux-persist/es/storage/createWebStorage' { + declare module.exports: any; +} + +declare module 'redux-persist/es/storage/getStorage' { + declare module.exports: any; +} + +declare module 'redux-persist/es/storage/index' { + declare module.exports: any; +} + +declare module 'redux-persist/es/storage/index.native' { + declare module.exports: any; +} + +declare module 'redux-persist/es/storage/session' { + declare module.exports: any; +} + +declare module 'redux-persist/es/types' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/constants' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/createMigrate' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/createPersistoid' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/createTransform' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/getStoredState' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/index' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/integration/getStoredStateMigrateV4' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/integration/react' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/persistCombineReducers' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/persistReducer' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/persistStore' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/purgeStoredState' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/stateReconciler/autoMergeLevel1' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/stateReconciler/autoMergeLevel2' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/stateReconciler/hardSet' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/storage/createWebStorage' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/storage/getStorage' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/storage/index' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/storage/index.native' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/storage/session' { + declare module.exports: any; +} + +declare module 'redux-persist/lib/types' { + declare module.exports: any; +} + +declare module 'redux-persist/src/constants' { + declare module.exports: any; +} + +declare module 'redux-persist/src/createMigrate' { + declare module.exports: any; +} + +declare module 'redux-persist/src/createPersistoid' { + declare module.exports: any; +} + +declare module 'redux-persist/src/createTransform' { + declare module.exports: any; +} + +declare module 'redux-persist/src/getStoredState' { + declare module.exports: any; +} + +declare module 'redux-persist/src/index' { + declare module.exports: any; +} + +declare module 'redux-persist/src/integration/getStoredStateMigrateV4' { + declare module.exports: any; +} + +declare module 'redux-persist/src/integration/react' { + declare module.exports: any; +} + +declare module 'redux-persist/src/persistCombineReducers' { + declare module.exports: any; +} + +declare module 'redux-persist/src/persistReducer' { + declare module.exports: any; +} + +declare module 'redux-persist/src/persistStore' { + declare module.exports: any; +} + +declare module 'redux-persist/src/purgeStoredState' { + declare module.exports: any; +} + +declare module 'redux-persist/src/stateReconciler/autoMergeLevel1' { + declare module.exports: any; +} + +declare module 'redux-persist/src/stateReconciler/autoMergeLevel2' { + declare module.exports: any; +} + +declare module 'redux-persist/src/stateReconciler/hardSet' { + declare module.exports: any; +} + +declare module 'redux-persist/src/storage/createWebStorage' { + declare module.exports: any; +} + +declare module 'redux-persist/src/storage/getStorage' { + declare module.exports: any; +} + +declare module 'redux-persist/src/storage/index' { + declare module.exports: any; +} + +declare module 'redux-persist/src/storage/index.native' { + declare module.exports: any; +} + +declare module 'redux-persist/src/storage/session' { + declare module.exports: any; +} + +declare module 'redux-persist/src/types' { + declare module.exports: any; +} + +// Filename aliases +declare module 'redux-persist/dist/redux-persist.js' { + declare module.exports: $Exports<'redux-persist/dist/redux-persist'>; +} +declare module 'redux-persist/dist/redux-persist.min.js' { + declare module.exports: $Exports<'redux-persist/dist/redux-persist.min'>; +} +declare module 'redux-persist/es/constants.js' { + declare module.exports: $Exports<'redux-persist/es/constants'>; +} +declare module 'redux-persist/es/createMigrate.js' { + declare module.exports: $Exports<'redux-persist/es/createMigrate'>; +} +declare module 'redux-persist/es/createPersistoid.js' { + declare module.exports: $Exports<'redux-persist/es/createPersistoid'>; +} +declare module 'redux-persist/es/createTransform.js' { + declare module.exports: $Exports<'redux-persist/es/createTransform'>; +} +declare module 'redux-persist/es/getStoredState.js' { + declare module.exports: $Exports<'redux-persist/es/getStoredState'>; +} +declare module 'redux-persist/es/index.js' { + declare module.exports: $Exports<'redux-persist/es/index'>; +} +declare module 'redux-persist/es/integration/getStoredStateMigrateV4.js' { + declare module.exports: $Exports<'redux-persist/es/integration/getStoredStateMigrateV4'>; +} +declare module 'redux-persist/es/integration/react.js' { + declare module.exports: $Exports<'redux-persist/es/integration/react'>; +} +declare module 'redux-persist/es/persistCombineReducers.js' { + declare module.exports: $Exports<'redux-persist/es/persistCombineReducers'>; +} +declare module 'redux-persist/es/persistReducer.js' { + declare module.exports: $Exports<'redux-persist/es/persistReducer'>; +} +declare module 'redux-persist/es/persistStore.js' { + declare module.exports: $Exports<'redux-persist/es/persistStore'>; +} +declare module 'redux-persist/es/purgeStoredState.js' { + declare module.exports: $Exports<'redux-persist/es/purgeStoredState'>; +} +declare module 'redux-persist/es/stateReconciler/autoMergeLevel1.js' { + declare module.exports: $Exports<'redux-persist/es/stateReconciler/autoMergeLevel1'>; +} +declare module 'redux-persist/es/stateReconciler/autoMergeLevel2.js' { + declare module.exports: $Exports<'redux-persist/es/stateReconciler/autoMergeLevel2'>; +} +declare module 'redux-persist/es/stateReconciler/hardSet.js' { + declare module.exports: $Exports<'redux-persist/es/stateReconciler/hardSet'>; +} +declare module 'redux-persist/es/storage/createWebStorage.js' { + declare module.exports: $Exports<'redux-persist/es/storage/createWebStorage'>; +} +declare module 'redux-persist/es/storage/getStorage.js' { + declare module.exports: $Exports<'redux-persist/es/storage/getStorage'>; +} +declare module 'redux-persist/es/storage/index.js' { + declare module.exports: $Exports<'redux-persist/es/storage/index'>; +} +declare module 'redux-persist/es/storage/index.native.js' { + declare module.exports: $Exports<'redux-persist/es/storage/index.native'>; +} +declare module 'redux-persist/es/storage/session.js' { + declare module.exports: $Exports<'redux-persist/es/storage/session'>; +} +declare module 'redux-persist/es/types.js' { + declare module.exports: $Exports<'redux-persist/es/types'>; +} +declare module 'redux-persist/lib/constants.js' { + declare module.exports: $Exports<'redux-persist/lib/constants'>; +} +declare module 'redux-persist/lib/createMigrate.js' { + declare module.exports: $Exports<'redux-persist/lib/createMigrate'>; +} +declare module 'redux-persist/lib/createPersistoid.js' { + declare module.exports: $Exports<'redux-persist/lib/createPersistoid'>; +} +declare module 'redux-persist/lib/createTransform.js' { + declare module.exports: $Exports<'redux-persist/lib/createTransform'>; +} +declare module 'redux-persist/lib/getStoredState.js' { + declare module.exports: $Exports<'redux-persist/lib/getStoredState'>; +} +declare module 'redux-persist/lib/index.js' { + declare module.exports: $Exports<'redux-persist/lib/index'>; +} +declare module 'redux-persist/lib/integration/getStoredStateMigrateV4.js' { + declare module.exports: $Exports<'redux-persist/lib/integration/getStoredStateMigrateV4'>; +} +declare module 'redux-persist/lib/integration/react.js' { + declare module.exports: $Exports<'redux-persist/lib/integration/react'>; +} +declare module 'redux-persist/lib/persistCombineReducers.js' { + declare module.exports: $Exports<'redux-persist/lib/persistCombineReducers'>; +} +declare module 'redux-persist/lib/persistReducer.js' { + declare module.exports: $Exports<'redux-persist/lib/persistReducer'>; +} +declare module 'redux-persist/lib/persistStore.js' { + declare module.exports: $Exports<'redux-persist/lib/persistStore'>; +} +declare module 'redux-persist/lib/purgeStoredState.js' { + declare module.exports: $Exports<'redux-persist/lib/purgeStoredState'>; +} +declare module 'redux-persist/lib/stateReconciler/autoMergeLevel1.js' { + declare module.exports: $Exports<'redux-persist/lib/stateReconciler/autoMergeLevel1'>; +} +declare module 'redux-persist/lib/stateReconciler/autoMergeLevel2.js' { + declare module.exports: $Exports<'redux-persist/lib/stateReconciler/autoMergeLevel2'>; +} +declare module 'redux-persist/lib/stateReconciler/hardSet.js' { + declare module.exports: $Exports<'redux-persist/lib/stateReconciler/hardSet'>; +} +declare module 'redux-persist/lib/storage/createWebStorage.js' { + declare module.exports: $Exports<'redux-persist/lib/storage/createWebStorage'>; +} +declare module 'redux-persist/lib/storage/getStorage.js' { + declare module.exports: $Exports<'redux-persist/lib/storage/getStorage'>; +} +declare module 'redux-persist/lib/storage/index.js' { + declare module.exports: $Exports<'redux-persist/lib/storage/index'>; +} +declare module 'redux-persist/lib/storage/index.native.js' { + declare module.exports: $Exports<'redux-persist/lib/storage/index.native'>; +} +declare module 'redux-persist/lib/storage/session.js' { + declare module.exports: $Exports<'redux-persist/lib/storage/session'>; +} +declare module 'redux-persist/lib/types.js' { + declare module.exports: $Exports<'redux-persist/lib/types'>; +} +declare module 'redux-persist/src/constants.js' { + declare module.exports: $Exports<'redux-persist/src/constants'>; +} +declare module 'redux-persist/src/createMigrate.js' { + declare module.exports: $Exports<'redux-persist/src/createMigrate'>; +} +declare module 'redux-persist/src/createPersistoid.js' { + declare module.exports: $Exports<'redux-persist/src/createPersistoid'>; +} +declare module 'redux-persist/src/createTransform.js' { + declare module.exports: $Exports<'redux-persist/src/createTransform'>; +} +declare module 'redux-persist/src/getStoredState.js' { + declare module.exports: $Exports<'redux-persist/src/getStoredState'>; +} +declare module 'redux-persist/src/index.js' { + declare module.exports: $Exports<'redux-persist/src/index'>; +} +declare module 'redux-persist/src/integration/getStoredStateMigrateV4.js' { + declare module.exports: $Exports<'redux-persist/src/integration/getStoredStateMigrateV4'>; +} +declare module 'redux-persist/src/integration/react.js' { + declare module.exports: $Exports<'redux-persist/src/integration/react'>; +} +declare module 'redux-persist/src/persistCombineReducers.js' { + declare module.exports: $Exports<'redux-persist/src/persistCombineReducers'>; +} +declare module 'redux-persist/src/persistReducer.js' { + declare module.exports: $Exports<'redux-persist/src/persistReducer'>; +} +declare module 'redux-persist/src/persistStore.js' { + declare module.exports: $Exports<'redux-persist/src/persistStore'>; +} +declare module 'redux-persist/src/purgeStoredState.js' { + declare module.exports: $Exports<'redux-persist/src/purgeStoredState'>; +} +declare module 'redux-persist/src/stateReconciler/autoMergeLevel1.js' { + declare module.exports: $Exports<'redux-persist/src/stateReconciler/autoMergeLevel1'>; +} +declare module 'redux-persist/src/stateReconciler/autoMergeLevel2.js' { + declare module.exports: $Exports<'redux-persist/src/stateReconciler/autoMergeLevel2'>; +} +declare module 'redux-persist/src/stateReconciler/hardSet.js' { + declare module.exports: $Exports<'redux-persist/src/stateReconciler/hardSet'>; +} +declare module 'redux-persist/src/storage/createWebStorage.js' { + declare module.exports: $Exports<'redux-persist/src/storage/createWebStorage'>; +} +declare module 'redux-persist/src/storage/getStorage.js' { + declare module.exports: $Exports<'redux-persist/src/storage/getStorage'>; +} +declare module 'redux-persist/src/storage/index.js' { + declare module.exports: $Exports<'redux-persist/src/storage/index'>; +} +declare module 'redux-persist/src/storage/index.native.js' { + declare module.exports: $Exports<'redux-persist/src/storage/index.native'>; +} +declare module 'redux-persist/src/storage/session.js' { + declare module.exports: $Exports<'redux-persist/src/storage/session'>; +} +declare module 'redux-persist/src/types.js' { + declare module.exports: $Exports<'redux-persist/src/types'>; +} diff --git a/package.json b/package.json index 5e94b280d..6a58d3781 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,8 @@ "react-test-renderer": "^16", "react-virtualized": "^9.13.0", "redux": "^4.0.0", + "redux-persist": "^5.10.0", + "redux-persist-transform-filter": "^0.0.18", "rsocket-core": "^0.0.6", "rsocket-tcp-server": "^0.0.6", "socket.io": "^2.0.4", diff --git a/src/init.js b/src/init.js index 1c2915ae7..01b5b96f7 100644 --- a/src/init.js +++ b/src/init.js @@ -14,15 +14,36 @@ import Logger from './fb-stubs/Logger.js'; import App from './App.js'; import BugReporter from './fb-stubs/BugReporter.js'; import {createStore} from 'redux'; +import {persistStore, persistReducer} from 'redux-persist'; +import createFilter from 'redux-persist-transform-filter'; +import storage from 'redux-persist/lib/storage/index.js'; +import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2'; import reducers from './reducers/index.js'; import dispatcher from './dispatcher/index.js'; import {setupMenuBar} from './MenuBar.js'; const path = require('path'); -const store = createStore( +const reducer: typeof reducers = persistReducer( + { + key: 'root', + stateReconciler: autoMergeLevel2, + transforms: [ + createFilter('connections', [ + 'userPreferredDevice', + 'userPreferredPlugin', + 'userPreferredApp', + ]), + ], + storage, + }, reducers, +); + +const store = createStore( + reducer, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(), ); +persistStore(store); const logger = new Logger(); const bugReporter = new BugReporter(logger); diff --git a/yarn.lock b/yarn.lock index af5965b89..4fdd6dfc8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3235,10 +3235,38 @@ lodash-es@^4.17.5: version "4.17.10" resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.10.tgz#62cd7104cdf5dd87f235a837f0ede0e8e5117e05" +lodash.clonedeep@^4.5.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef" + +lodash.forin@^4.4.0: + version "4.4.0" + resolved "https://registry.yarnpkg.com/lodash.forin/-/lodash.forin-4.4.0.tgz#5d3f20ae564011fbe88381f7d98949c9c9519731" + +lodash.get@^4.4.2: + version "4.4.2" + resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99" + +lodash.isempty@^4.4.0: + version "4.4.0" + resolved "https://registry.yarnpkg.com/lodash.isempty/-/lodash.isempty-4.4.0.tgz#6f86cbedd8be4ec987be9aaf33c9684db1b31e7e" + +lodash.pickby@^4.6.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/lodash.pickby/-/lodash.pickby-4.6.0.tgz#7dea21d8c18d7703a27c704c15d3b84a67e33aff" + +lodash.set@^4.3.2: + version "4.3.2" + resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23" + lodash.sortby@^4.7.0: version "4.7.0" resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438" +lodash.unset@^4.5.2: + version "4.5.2" + resolved "https://registry.yarnpkg.com/lodash.unset/-/lodash.unset-4.5.2.tgz#370d1d3e85b72a7e1b0cdf2d272121306f23e4ed" + lodash@^4.0.1, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.3.0: version "4.17.10" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7" @@ -4150,6 +4178,22 @@ redent@^1.0.0: indent-string "^2.1.0" strip-indent "^1.0.1" +redux-persist-transform-filter@^0.0.18: + version "0.0.18" + resolved "https://registry.yarnpkg.com/redux-persist-transform-filter/-/redux-persist-transform-filter-0.0.18.tgz#bc9901a0267bd64631099b4e7bb4d48c00647418" + dependencies: + lodash.clonedeep "^4.5.0" + lodash.forin "^4.4.0" + lodash.get "^4.4.2" + lodash.isempty "^4.4.0" + lodash.pickby "^4.6.0" + lodash.set "^4.3.2" + lodash.unset "^4.5.2" + +redux-persist@^5.10.0: + version "5.10.0" + resolved "https://registry.yarnpkg.com/redux-persist/-/redux-persist-5.10.0.tgz#5d8d802c5571e55924efc1c3a9b23575283be62b" + redux@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.0.tgz#aa698a92b729315d22b34a0553d7e6533555cc03"