Skip to content

Commit

Permalink
fix: rebase with master
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham2811 committed Nov 5, 2024
2 parents dff8302 + 23f62c8 commit 992ec79
Show file tree
Hide file tree
Showing 170 changed files with 2,028 additions and 6,563 deletions.
4,623 changes: 1,670 additions & 2,953 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions packages/subapp-redux/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"name": "subapp-redux",
"entries": [
{
"version": "3.0.0",
"tag": "subapp-redux_v3.0.0",
"date": "Fri, 25 Oct 2024 17:22:04 GMT",
"comments": {
"major": [
{
"comment": "Upgrade internal implementation to use @reduxjs/toolkit"
}
]
}
},
{
"version": "2.3.0",
"tag": "subapp-redux_v2.3.0",
Expand Down
9 changes: 8 additions & 1 deletion packages/subapp-redux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Change Log - subapp-redux

This log was last generated on Fri, 19 Apr 2024 20:43:30 GMT and should not be manually modified.
This log was last generated on Fri, 25 Oct 2024 17:22:04 GMT and should not be manually modified.

## 3.0.0
Fri, 25 Oct 2024 17:22:04 GMT

### Breaking changes

- Upgrade internal implementation to use @reduxjs/toolkit

## 2.3.0
Fri, 19 Apr 2024 20:43:30 GMT
Expand Down
4 changes: 2 additions & 2 deletions packages/subapp-redux/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "subapp-redux",
"version": "2.3.0",
"version": "3.0.0",
"description": "Electrode subapp redux support",
"module": "dist/dev/index.js",
"main": "lib/index.js",
Expand Down Expand Up @@ -38,13 +38,13 @@
"@babel/preset-react": "^7.16.7",
"@babel/register": "^7.17.7",
"@babel/runtime": "^7.17.9",
"@reduxjs/toolkit": ">= 2",
"@xarc/run": "^1.1.1",
"babel-preset-minify": "^0.5.1",
"electrode-archetype-njs-module-dev": "^3.0.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.0.1",
"redux": "^4.2.0",
"run-verify": "^1.2.6",
"subapp-pkg-util": "0.0.1"
},
Expand Down
21 changes: 12 additions & 9 deletions packages/subapp-redux/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ setStoreContainer(window);
// client side function to start a subapp with redux support
//
export function reduxRenderStart(options) {
const store = options._store || options.reduxCreateStore(options.initialState);
const store =
options._store || options.reduxCreateStore(options.initialState);
const { Component, props } = options;

let subappRoot;

if (options.serverSideRendering) {
subappRoot = hydrateRoot(options.element,
subappRoot = hydrateRoot(
options.element,
<Provider store={store}>
<Component {...props} />
</Provider>
);
} else {
subappRoot = createRoot(options.element)
subappRoot = createRoot(options.element);
subappRoot.render(
<Provider store={store}>
<Component {...props} />
Expand All @@ -42,11 +44,12 @@ export function reduxRenderStart(options) {
// onLoadStartElement - the HTML element to render into upon loaded by the browser
//
export function reduxLoadSubApp(info) {
const renderStart = function(instance, element) {
const renderStart = function (instance, element) {
const initialState = instance._prepared || instance.initialState;
const reduxCreateStore = instance.reduxCreateStore || this.info.reduxCreateStore;
const reduxCreateStore =
instance.reduxCreateStore || this.info.reduxCreateStore;
const Component = this.info.StartComponent || this.info.Component;
const props = instance.props || {}
const props = instance.props || {};

const { store, subappRoot } = reduxRenderStart({
_store: instance._store,
Expand All @@ -55,7 +58,7 @@ export function reduxLoadSubApp(info) {
Component,
serverSideRendering: instance.serverSideRendering,
element,
props
props,
});

instance._store = store;
Expand All @@ -64,7 +67,7 @@ export function reduxLoadSubApp(info) {
};

const extras = {
__redux: true
__redux: true,
};

if (!info.reduxCreateStore) {
Expand All @@ -73,7 +76,7 @@ export function reduxLoadSubApp(info) {

return loadSubApp(
Object.assign(extras, info, {
reduxCreateStore: getReduxCreateStore(info)
reduxCreateStore: getReduxCreateStore(info),
}),
renderStart
);
Expand Down
58 changes: 35 additions & 23 deletions packages/subapp-redux/src/shared.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createStore, combineReducers } from "redux";
import { configureStore, combineReducers } from "@reduxjs/toolkit";

//
// - stores can be shared between subapps with reduxShareStore flag
Expand Down Expand Up @@ -75,7 +75,10 @@ const combineSharedReducers = (info, container, reducers) => {
};

function replaceReducer(newReducers, info, storeContainer) {
let { store, reducerContainer } = getSharedStore(info.reduxShareStore, storeContainer);
let { store, reducerContainer } = getSharedStore(
info.reduxShareStore,
storeContainer
);
const reducer = combineSharedReducers(info, reducerContainer, newReducers);
return store[originalReplaceReducerSym](reducer);
}
Expand All @@ -88,25 +91,27 @@ function createSharedStore(initialState, info, storeContainer) {
info._genReduxCreateStore || !info.reduxCreateStore,
`${WHEN_SHARED_MSG}, you cannot have reduxCreateStore`
);
let { store, reducerContainer } = getSharedStore(sharedStoreName, storeContainer);
let { store, reducerContainer } = getSharedStore(
sharedStoreName,
storeContainer
);
if (store) {
// TODO: redux doesn't have a way to set initial state
// after store's created? What can we do about this?
replaceReducer(info.reduxReducers, info, storeContainer);
} else {
reducerContainer = newReducerContainer();
if (info.reduxEnhancer && info.reduxEnhancer instanceof Function) {
store = createStore(
combineSharedReducers(info, reducerContainer, info.reduxReducers),
initialState,
info.reduxEnhancer()
);
} else {
store = createStore(
combineSharedReducers(info, reducerContainer, info.reduxReducers),
initialState
);
}
store = configureStore({
reducer: combineSharedReducers(
info,
reducerContainer,
info.reduxReducers
),
preloadedState: initialState,
enhancers: info.reduxEnhancer,
middleware: info.middleware,
});

store[originalReplaceReducerSym] = store.replaceReducer;
//
// TODO: better handling of a replaceReducer that takes extra params
Expand All @@ -124,7 +129,11 @@ function createSharedStore(initialState, info, storeContainer) {
return replaceReducer(reducers, info2, storeContainer2);
};
}
setSharedStore(sharedStoreName, { store, reducerContainer }, storeContainer);
setSharedStore(
sharedStoreName,
{ store, reducerContainer },
storeContainer
);
return store;
}

Expand All @@ -142,17 +151,20 @@ function createSharedStore(initialState, info, storeContainer) {
} else if (reducerType === "object") {
reducer = combineReducers(info.reduxReducers);
} else {
reducer = x => x;
reducer = (x) => x;
}

if (info.reduxEnhancer && info.reduxEnhancer instanceof Function) {
return createStore(reducer, initialState, info.reduxEnhancer());
}
return createStore(reducer, initialState);
return configureStore({
reducer,
preloadedState: initialState,
enhancers: info.reduxEnhancer,
middleware: info.middleware,
});
}

function getReduxCreateStore(info) {
return (initialState, storeContainer) => createSharedStore(initialState, info, storeContainer);
return (initialState, storeContainer) =>
createSharedStore(initialState, info, storeContainer);
}

export {
Expand All @@ -161,5 +173,5 @@ export {
createSharedStore,
getSharedStore,
setSharedStore,
clearSharedStore
clearSharedStore,
};
Loading

0 comments on commit 992ec79

Please sign in to comment.