feat: redux + rr6 data router

This commit is contained in:
cha0s 2024-02-20 05:19:58 -06:00
parent 07b64dc217
commit cda4e1c3bb
4 changed files with 140 additions and 123 deletions

214
package-lock.json generated
View File

@ -13088,6 +13088,11 @@
"@babel/runtime": "^7.9.2"
}
},
"node_modules/redux-data-router": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/redux-data-router/-/redux-data-router-1.0.0.tgz",
"integrity": "sha512-EzpitBfKAX78ZGEmjgqlfYuZlfaXuG1JD+RvnuxR48aGxZo4iuqyTzEiaxLxN02Z4j/X1EENwy9pvwBbtC0mDw=="
},
"node_modules/redux-first-history": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/redux-first-history/-/redux-first-history-5.1.1.tgz",
@ -16677,7 +16682,7 @@
},
"packages/build": {
"name": "@flecks/build",
"version": "4.1.2",
"version": "4.1.3",
"license": "MIT",
"dependencies": {
"@babel/core": "^7.12.10",
@ -16688,7 +16693,7 @@
"@babel/preset-env": "^7.12.11",
"@babel/traverse": "^7.17.0",
"@babel/types": "^7.17.0",
"@flecks/core": "^4.2.2",
"@flecks/core": "^4.2.3",
"babel-loader": "^9.1.3",
"babel-merge": "^3.0.0",
"chai": "4.2.0",
@ -16746,7 +16751,7 @@
},
"packages/core": {
"name": "@flecks/core",
"version": "4.2.2",
"version": "4.2.3",
"license": "MIT",
"dependencies": {
"callsites": "^3.1.0",
@ -16802,10 +16807,10 @@
},
"packages/create-app": {
"name": "@flecks/create-app",
"version": "4.0.11",
"version": "4.0.12",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.2.2",
"@flecks/core": "^4.2.3",
"commander": "11.1.0",
"validate-npm-package-name": "^3.0.0"
},
@ -16813,8 +16818,8 @@
"create-app": "build/cli.js"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/fleck": "^4.1.2"
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3"
}
},
"packages/create-app/node_modules/builtins": {
@ -16832,45 +16837,45 @@
},
"packages/create-fleck": {
"name": "@flecks/create-fleck",
"version": "4.0.10",
"version": "4.0.11",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.2.2",
"@flecks/core": "^4.2.3",
"commander": "11.1.0"
},
"bin": {
"create-fleck": "build/cli.js"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/fleck": "^4.1.2"
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3"
}
},
"packages/db": {
"name": "@flecks/db",
"version": "4.1.2",
"version": "4.1.3",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.2.2",
"@flecks/core": "^4.2.3",
"sequelize": "^6.3.5",
"sqlite3": "^5.0.2"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/fleck": "^4.1.2"
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3"
}
},
"packages/docker": {
"name": "@flecks/docker",
"version": "4.0.10",
"version": "4.0.11",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.2.2",
"@flecks/core": "^4.2.3",
"debug": "^4.3.3"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/fleck": "^4.1.2"
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3"
}
},
"packages/docker/node_modules/debug": {
@ -16891,47 +16896,47 @@
},
"packages/dox": {
"name": "@flecks/dox",
"version": "4.0.10",
"version": "4.0.11",
"license": "MIT",
"dependencies": {
"@babel/core": "^7.17.2",
"@babel/traverse": "^7.17.0",
"@babel/types": "^7.17.0",
"@flecks/core": "^4.2.2",
"@flecks/core": "^4.2.3",
"comment-parser": "^1.3.0",
"rimraf": "^5.0.5"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/fleck": "^4.1.2"
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3"
}
},
"packages/electron": {
"name": "@flecks/electron",
"version": "4.0.10",
"version": "4.0.11",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.2.2",
"@flecks/core": "^4.2.3",
"electron": "^28.1.4",
"electron-devtools-installer": "^3.2.0"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/fleck": "^4.1.2"
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3"
}
},
"packages/fleck": {
"name": "@flecks/fleck",
"version": "4.1.2",
"version": "4.1.3",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.2.2",
"@flecks/core": "^4.2.3",
"babel-merge": "^3.0.0",
"debug": "^4.3.3",
"mocha": "^10.2.0"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/build": "^4.1.3",
"chai": "4.2.0"
}
},
@ -16953,89 +16958,91 @@
},
"packages/headless": {
"name": "@flecks/headless",
"version": "4.0.2",
"version": "4.0.3",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.0.0"
"@flecks/core": "^4.2.3"
},
"devDependencies": {
"@flecks/build": "^4.0.0",
"@flecks/fleck": "^4.0.0",
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3",
"puppeteer": "^22.0.0"
}
},
"packages/passport": {
"name": "@flecks/passport",
"version": "4.0.10",
"version": "4.0.11",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.2.2",
"@flecks/db": "^4.1.2",
"@flecks/redux": "^4.0.10",
"@flecks/session": "^4.0.10",
"@flecks/core": "^4.2.3",
"@flecks/db": "^4.1.3",
"@flecks/redux": "^4.0.11",
"@flecks/session": "^4.0.11",
"passport": "^0.7.0"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/fleck": "^4.1.2"
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3"
}
},
"packages/passport-local": {
"name": "@flecks/passport-local",
"version": "4.0.10",
"version": "4.0.11",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.2.2",
"@flecks/passport": "^4.0.10",
"@flecks/core": "^4.2.3",
"@flecks/passport": "^4.0.11",
"bcrypt": "^5.1.1",
"passport-local": "^1.0.0"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/fleck": "^4.1.2"
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3"
}
},
"packages/passport-local-react": {
"name": "@flecks/passport-local-react",
"version": "4.0.12",
"version": "4.0.13",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.2.2",
"@flecks/passport-local": "^4.0.10",
"@flecks/passport-react": "^4.0.12",
"@flecks/react": "^4.0.12"
"@flecks/core": "^4.2.3",
"@flecks/passport-local": "^4.0.11",
"@flecks/passport-react": "^4.0.13",
"@flecks/react": "^4.0.13"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/fleck": "^4.1.2"
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3"
}
},
"packages/passport-react": {
"name": "@flecks/passport-react",
"version": "4.0.12",
"version": "4.0.13",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.2.2",
"@flecks/passport": "^4.0.10",
"@flecks/react": "^4.0.12",
"@flecks/react-redux": "^4.0.12",
"@flecks/web": "^4.1.4"
"@flecks/core": "^4.2.3",
"@flecks/passport": "^4.0.11",
"@flecks/react": "^4.0.13",
"@flecks/react-redux": "^4.0.13",
"@flecks/web": "^4.1.5"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/fleck": "^4.1.2"
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3"
}
},
"packages/react": {
"name": "@flecks/react",
"version": "4.0.12",
"version": "4.0.13",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
"@babel/preset-react": "^7.23.3",
"@flecks/core": "^4.2.2",
"@flecks/web": "^4.1.4",
"@flecks/core": "^4.2.3",
"@flecks/redux": "^4.0.11",
"@flecks/web": "^4.1.5",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
"@remix-run/router": "1.15.1",
"babel-merge": "^3.0.0",
"classnames": "^2.3.1",
"history": "^5.3.0",
@ -17047,58 +17054,59 @@
"react-router": "6.22.1",
"react-router-dom": "6.22.1",
"react-tabs": "^6.0.2",
"redux-data-router": "^1.0.0",
"redux-first-history": "5.1.1"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/fleck": "^4.1.2"
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3"
}
},
"packages/react-redux": {
"name": "@flecks/react-redux",
"version": "4.0.12",
"version": "4.0.13",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.2.2",
"@flecks/react": "^4.0.12",
"@flecks/redux": "^4.0.10",
"@flecks/core": "^4.2.3",
"@flecks/react": "^4.0.13",
"@flecks/redux": "^4.0.11",
"react-redux": "^7.2.2"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/fleck": "^4.1.2"
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3"
}
},
"packages/redis": {
"name": "@flecks/redis",
"version": "4.0.10",
"version": "4.0.11",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.2.2",
"@flecks/core": "^4.2.3",
"@socket.io/redis-adapter": "7.1.0",
"connect-redis": "^5.0.0",
"express-session": "^1.17.1",
"redis": "4.0.3"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/fleck": "^4.1.2"
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3"
}
},
"packages/redux": {
"name": "@flecks/redux",
"version": "4.0.10",
"version": "4.0.11",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.2.2",
"@flecks/core": "^4.2.3",
"@reduxjs/toolkit": "^1.5.0",
"debug": "^4.3.3",
"lodash.throttle": "^4.1.1",
"reduce-reducers": "^1.0.4"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/fleck": "^4.1.2"
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3"
}
},
"packages/redux/node_modules/debug": {
@ -17119,51 +17127,51 @@
},
"packages/repl": {
"name": "@flecks/repl",
"version": "4.1.2",
"version": "4.1.3",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.2.2",
"@flecks/core": "^4.2.3",
"command-exists": "^1.2.9",
"debug": "4.3.1"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/fleck": "^4.1.2"
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3"
}
},
"packages/server": {
"name": "@flecks/server",
"version": "4.1.2",
"version": "4.1.3",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.2.2"
"@flecks/core": "^4.2.3"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/fleck": "^4.1.2"
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3"
}
},
"packages/session": {
"name": "@flecks/session",
"version": "4.0.10",
"version": "4.0.11",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.2.2",
"@flecks/core": "^4.2.3",
"express": "^4.18.2",
"express-session": "^1.17.3"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/fleck": "^4.1.2"
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3"
}
},
"packages/socket": {
"name": "@flecks/socket",
"version": "4.0.12",
"version": "4.0.13",
"license": "MIT",
"dependencies": {
"@flecks/core": "^4.2.2",
"@flecks/react": "^4.0.12",
"@flecks/core": "^4.2.3",
"@flecks/react": "^4.0.13",
"msgpack-lite": "^0.1.26",
"proxy-addr": "^2.0.6",
"schemapack": "^1.4.2",
@ -17171,19 +17179,19 @@
"socket.io-client": "^4.1.2"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/fleck": "^4.1.2"
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3"
}
},
"packages/web": {
"name": "@flecks/web",
"version": "4.1.4",
"version": "4.1.5",
"license": "MIT",
"dependencies": {
"@babel/parser": "^7.17.0",
"@babel/types": "^7.17.0",
"@flecks/core": "^4.2.2",
"@flecks/server": "^4.1.2",
"@flecks/core": "^4.2.3",
"@flecks/server": "^4.1.3",
"@webpack-cli/serve": "^2.0.5",
"add-asset-html-webpack-plugin": "^6.0.0",
"assert": "^2.1.0",
@ -17215,9 +17223,9 @@
"webpack-dev-server": "^4.15.1"
},
"devDependencies": {
"@flecks/build": "^4.1.2",
"@flecks/fleck": "^4.1.2",
"@flecks/headless": "^4.0.2"
"@flecks/build": "^4.1.3",
"@flecks/fleck": "^4.1.3",
"@flecks/headless": "^4.0.3"
}
}
}

View File

@ -33,8 +33,10 @@
"dependencies": {
"@babel/preset-react": "^7.23.3",
"@flecks/core": "^4.2.3",
"@flecks/redux": "^4.0.11",
"@flecks/web": "^4.1.5",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
"@remix-run/router": "1.15.1",
"babel-merge": "^3.0.0",
"classnames": "^2.3.1",
"history": "^5.3.0",
@ -46,6 +48,7 @@
"react-router": "6.22.1",
"react-router-dom": "6.22.1",
"react-tabs": "^6.0.2",
"redux-data-router": "^1.0.0",
"redux-first-history": "5.1.1"
},
"devDependencies": {

View File

@ -1,16 +1,12 @@
import {
createBrowserRouter,
matchRoutes,
RouterProvider,
} from 'react-router-dom';
import {performReactRefresh} from 'react-refresh/runtime';
import {createBrowserRouter, matchRoutes, RouterProvider} from 'react-router-dom';
import {createEnhancer, reducer} from 'redux-data-router';
export const hooks = {
'@flecks/core.hmr.hook': (hook, fleck, flecks) => {
'@flecks/core.hmr.hook': (hook, fleck, {reactRouter}) => {
if ('@flecks/react/router.routes' === hook) {
// Routes got HMR'd.
flecks.reactRouter.invalidate();
reactRouter.invalidate();
}
},
'@flecks/core.reload': (fleck, config, flecks) => {
@ -22,26 +18,35 @@ export const hooks = {
throw new Error('root changed');
}
},
'@flecks/react.roots': async (req, res, flecks) => {
'@flecks/core.starting': async (flecks) => {
const {root} = flecks.get('@flecks/react/router');
const {base: basename} = flecks.get('@flecks/web');
const routes = await flecks.invokeFleck('@flecks/react/router.routes', root);
// Determine if any of the initial routes are lazy
const lazyMatches = matchRoutes(routes, window.location)?.filter(({route}) => route.lazy);
// Load the lazy matches and update the routes before creating the router
// so we can hydrate the SSR-rendered content synchronously.
if (lazyMatches && lazyMatches?.length > 0) {
flecks.reactRouter.router = createBrowserRouter(routes, {basename});
},
'@flecks/react.roots': async (req, res, {reactRouter: {router}}) => {
// Determine if any of the initial routes are lazy and update them before creating the router
// provider so we can hydrate the SSR-rendered content synchronously.
const lazyMatches = matchRoutes(router.routes, window.location)
?.filter(({route}) => route.lazy) || [];
if (lazyMatches.length > 0) {
await Promise.all(
lazyMatches.map(async (m) => {
Object.entries(await m.route.lazy())
lazyMatches.map(async ({route}) => {
Object.entries(await route.lazy())
.forEach(([name, value]) => {
m.route[name] = value;
route[name] = value;
});
delete m.route.lazy;
delete route.lazy;
}),
);
}
flecks.reactRouter.router = createBrowserRouter(routes);
return [RouterProvider, {router: flecks.reactRouter.router}];
return [RouterProvider, {router}];
},
'@flecks/redux.slices': () => ({
router: reducer,
}),
'@flecks/redux.store': ({enhancers}, {reactRouter: {router}}) => {
enhancers.push(createEnhancer(router));
},
};

View File

@ -1,6 +1,7 @@
import {createRoutesFromFiletree, createRoutesFromContext} from './filetree-router';
export * from 'react-router-dom';
export * from 'redux-data-router';
export {createRoutesFromFiletree, createRoutesFromContext};