-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[major] update create-app to use subapp2 demo
- Loading branch information
Showing
15 changed files
with
215 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { declareSubApp, xarcV2 } from "@xarc/react"; | ||
|
||
export const home = declareSubApp({ | ||
name: "home", | ||
getModule: () => import("./home") | ||
}); | ||
|
||
export const Demo2 = declareSubApp({ | ||
name: "demo2", | ||
getModule: () => import("./demo2") | ||
}); | ||
|
||
xarcV2.debug("app.tsx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { React, ReactSubApp } from "@xarc/react"; | ||
|
||
const Demo1 = props => { | ||
return ( | ||
<div style={{ padding: "5px", border: "solid", marginLeft: "15%", marginRight: "15%" }}> | ||
<p>subapp demo1</p> | ||
props: {JSON.stringify(props)} | ||
<p> | ||
<a href="https://www.electrode.io/electrode/">Electrode Docs</a> | ||
</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export const subapp: ReactSubApp = { | ||
Component: Demo1 | ||
}; |
21 changes: 0 additions & 21 deletions
21
packages/xarc-create-app/template/src/demo1/subapp-demo1.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// A more complicate demo subapp using Redux | ||
// | ||
// Note: using redux requires top level Redux store initialization so if another | ||
// subapp tries to use this as a dynamic component, then it must also uses redux and | ||
// provides the redux top level store facility. | ||
// | ||
|
||
import { React, ReactSubApp } from "@xarc/react"; | ||
import { reduxFeature, connect } from "@xarc/react-redux"; | ||
export { reduxReducers } from "./reducers"; | ||
|
||
const incNumber = () => { | ||
return { | ||
type: "INC_NUMBER" | ||
}; | ||
}; | ||
|
||
const decNumber = () => { | ||
return { | ||
type: "DEC_NUMBER" | ||
}; | ||
}; | ||
|
||
const Demo2 = props => { | ||
const { value, dispatch } = props; | ||
|
||
return ( | ||
<div> | ||
<div | ||
style={{ | ||
padding: "5px", | ||
marginTop: "15px", | ||
border: "solid", | ||
marginLeft: "15%", | ||
marginRight: "15%" | ||
}} | ||
> | ||
<h2>subapp demo2 with Redux</h2> | ||
Redux State Demo: <button onClick={() => dispatch(decNumber())}>≪</button> | ||
{value} | ||
<button onClick={() => dispatch(incNumber())}>≫</button> | ||
</div> | ||
<p style={{ textAlign: "center" }}>© {new Date().getFullYear()} Your (Company) name here</p> | ||
</div> | ||
); | ||
}; | ||
|
||
const mapStateToProps = state => { | ||
return { value: state.number.value }; | ||
}; | ||
|
||
export const subapp: ReactSubApp = { | ||
Component: connect(mapStateToProps, dispatch => ({ dispatch }))(Demo2), | ||
wantFeatures: [ | ||
reduxFeature({ | ||
React, | ||
shareStore: true, | ||
reducers: true, // true => read the reduxReducers export from this file | ||
prepare: async initialState => { | ||
return { initialState: initialState || { number: { value: 999 } } }; | ||
} | ||
}) | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 0 additions & 51 deletions
51
packages/xarc-create-app/template/src/demo2/subapp-demo2.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { React, ReactSubApp, createDynamicComponent, staticPropsFeature } from "@xarc/react"; | ||
import electrodePng from "../../static/electrode.png"; | ||
import { message } from "./message"; | ||
|
||
export const Demo1 = createDynamicComponent( | ||
{ | ||
name: "demo1", | ||
getModule: () => import("../demo1") | ||
}, | ||
{ ssr: true } | ||
); | ||
|
||
const Home = props => { | ||
return ( | ||
<div style={{ textAlign: "center" }}> | ||
<h1> | ||
<a href="https://www.electrode.io"> | ||
Electrode <img src={electrodePng} /> | ||
</a> | ||
</h1> | ||
<p>{message}</p> | ||
<p>props: {JSON.stringify(props)}</p> | ||
<h1>Demo1 subapp as a dynamic component in Home</h1> | ||
<Demo1 /> | ||
</div> | ||
); | ||
}; | ||
|
||
export const subapp: ReactSubApp = { | ||
Component: Home, | ||
wantFeatures: [ | ||
staticPropsFeature({ | ||
serverModule: require.resolve("./static-props") | ||
}) | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const message = "Welcome to xarc React Application"; |
11 changes: 11 additions & 0 deletions
11
packages/xarc-create-app/template/src/home/static-props.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const maxDelay = 50; | ||
|
||
export async function getStaticProps() { | ||
const delay = Math.floor(Math.random() * maxDelay); | ||
return new Promise(resolve => { | ||
return setTimeout( | ||
() => resolve({ props: { message: "Hello from static props", delay } }), | ||
delay | ||
); | ||
}); | ||
} |
15 changes: 0 additions & 15 deletions
15
packages/xarc-create-app/template/src/home/subapp-home.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.