Skip to content

Commit 66cc1fc

Browse files
committed
CodeSplitter to MDEE package
1 parent b81c136 commit 66cc1fc

File tree

10 files changed

+780
-17777
lines changed

10 files changed

+780
-17777
lines changed

generators/microsoft-employee-experience-generator/examples/package-lock.json

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generators/microsoft-employee-experience-generator/examples/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
"@fluentui/style-utilities": "^8.6.5",
2727
"@fluentui/react": "^8.64.2",
2828
"@m365-admin/customizations": "^7.3.2",
29-
"@micro-frontend-react/employee-experience": "../../../extensions/microsoft-employee-experience",
29+
"@micro-frontend-react/employee-experience": "1.0.11",
3030
"@microsoft/myhub_webauth_sdk": "^0.0.1-Preview",
31-
"@ms-ofb/officebrowserfeedback": "^1.8.9",
31+
"@ms-ofb/officebrowserfeedback": "2.1.0",
3232
"@uifabric/charting": "^4.20.12",
3333
"@redux-devtools/extension": "^3.2.2",
3434
"axios": "^0.26.1",

generators/microsoft-employee-experience-generator/examples/src/Routes.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ export function Routes(): React.ReactElement {
2020
name: 'DynamicSubRoutes',
2121
}}
2222
/>
23+
<RouteComponentProvider
24+
path="/codesplitting"
25+
config={{
26+
script: '/bundles/code-splitting.js',
27+
name: 'CodeSplitting',
28+
}}
29+
/>
2330
</Switch>
2431
);
2532
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { Context, withContext } from '@micro-frontend-react/employee-experience/lib/Context';
2+
import { IEmployeeExperienceContext } from '@micro-frontend-react/employee-experience/lib/IEmployeeExperienceContext';
3+
import { getFeature, getPageLoadFeature } from '@micro-frontend-react/employee-experience/lib/UsageTelemetryHelper';
4+
import { useDynamicReducer } from '@micro-frontend-react/employee-experience/lib/useDynamicReducer';
5+
import { usePageTitle } from '@micro-frontend-react/employee-experience/lib/usePageTitle';
6+
import { usePageTracking } from '@micro-frontend-react/employee-experience/lib/usePageTracking';
7+
import * as React from 'react';
8+
import { CodeSplitter } from '@micro-frontend-react/employee-experience/lib/CodeSplitter';
9+
import * as Styled from '../Shared/Layout';
10+
import { requestMyProfile } from '../Shared/SharedExample.actions';
11+
import {
12+
sharedExampleInitialState,
13+
sharedExampleReducer,
14+
sharedExampleReducerName,
15+
} from '../Shared/SharedExample.reducer';
16+
import { sharedExampleSagas } from '../Shared/SharedExample.sagas';
17+
import { IExampleAppState } from '../Shared/SharedExample.types';
18+
19+
function CodeSplitting(): React.ReactElement {
20+
const feature = getFeature(__APP_NAME__, 'CodeSplitting');
21+
usePageTracking(getPageLoadFeature(feature));
22+
usePageTitle(`CodeSplitting - ${__APP_NAME__}`);
23+
24+
useDynamicReducer(sharedExampleReducerName, sharedExampleReducer, [sharedExampleSagas]);
25+
26+
const { useSelector, dispatch } = React.useContext(Context as React.Context<IEmployeeExperienceContext>);
27+
const { profile, isLoading, hasError, errorMessage } = useSelector(
28+
(state: IExampleAppState) => state.dynamic?.[sharedExampleReducerName] || sharedExampleInitialState
29+
);
30+
31+
React.useEffect(() => {
32+
dispatch(requestMyProfile());
33+
}, [dispatch]);
34+
35+
return (
36+
<Styled.Container>
37+
<Styled.PageHeading>Micro-Frontend Code Splitting</Styled.PageHeading>
38+
<Styled.PageDescription>
39+
Example of further splitting Micro-Frontend code into smaller chunks
40+
</Styled.PageDescription>
41+
42+
<Styled.SectionTitle>My Profile</Styled.SectionTitle>
43+
44+
{!profile && isLoading && 'Loading...'}
45+
{hasError && errorMessage}
46+
{!isLoading && !hasError && profile && (
47+
<CodeSplitter
48+
name="MyProfile"
49+
import={async () =>
50+
import(
51+
// webpackChunkName: 'my-profile'
52+
'./MyProfile'
53+
)
54+
}
55+
props={{ profile }}
56+
/>
57+
)}
58+
</Styled.Container>
59+
);
60+
}
61+
62+
const connected = withContext(CodeSplitting);
63+
export { connected as CodeSplitting };
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Persona, PersonaSize } from '@micro-frontend-react/employee-experience/lib/Persona';
2+
import * as React from 'react';
3+
import { IProfile } from '../Shared/SharedExample.types';
4+
5+
export function MyProfile(props: { profile: IProfile }): React.ReactElement {
6+
const { profile } = props;
7+
8+
return (
9+
<div>
10+
<Persona size={PersonaSize.size100} />
11+
<div>Name: {profile.displayName}</div>
12+
<div>title: {profile.jobTitle}</div>
13+
</div>
14+
);
15+
}

generators/microsoft-employee-experience-generator/examples/src/navConfig.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ export const navConfig = [
99
icon: 'Home',
1010
},
1111
{
12-
key: 4,
12+
key: 2,
1313
name: 'Dynamic + Sub Routes',
1414
href: '/dynamic-sub-routes',
1515
icon: 'Thunderstorms',
1616
},
17+
{
18+
key: 3,
19+
name: 'CodeSplitting',
20+
href: '/codesplitting',
21+
icon: 'Thunderstorms',
22+
},
1723
],
1824
},
1925
];

generators/microsoft-employee-experience-generator/examples/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const microFrontendEntries = {
3333

3434
'dynamic-redux-hooks': './src/Samples/DynamicReduxHooks/DynamicReduxHooks.tsx',
3535
'dynamic-sub-routes': './src/Samples/DynamicSubRoutes/DynamicSubRoutes.tsx',
36+
'code-splitting': './src/Samples/CodeSplitting/CodeSplitting.tsx',
3637
'dynamic-route-param-consumer': './src/Samples/DynamicSubRoutes/DynamicRouteParamConsumer.tsx',
3738
};
3839

0 commit comments

Comments
 (0)