mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-29 04:50:14 +00:00
Add the first redux action to the modern skin codebase
This commit is contained in:
parent
86684cd0ce
commit
1bb5195e4b
5 changed files with 26 additions and 5 deletions
5
modern/src/Actions.ts
Normal file
5
modern/src/Actions.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { MakiTree, ModernAction } from "./types";
|
||||
|
||||
export function setMakiTree(makiTree: MakiTree): ModernAction {
|
||||
return { type: "SET_MAKI_TREE", makiTree };
|
||||
}
|
||||
|
|
@ -6,8 +6,11 @@ import initialize from "./initialize";
|
|||
import System from "./runtime/System";
|
||||
import runtime from "./runtime";
|
||||
import { run } from "./maki-interpreter/virtualMachine";
|
||||
import * as Actions from "./Actions";
|
||||
import * as Selectors from "./Selectors";
|
||||
// import simpleSkin from "../skins/simple.wal";
|
||||
import cornerSkin from "../skins/CornerAmp_Redux.wal";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
|
||||
async function getSkin() {
|
||||
const resp = await fetch(cornerSkin);
|
||||
|
|
@ -337,7 +340,8 @@ function XmlNode({ node }) {
|
|||
}
|
||||
|
||||
function App() {
|
||||
const [data, setData] = React.useState(null);
|
||||
const dispatch = useDispatch();
|
||||
const data = useSelector(Selectors.getMakiTree);
|
||||
React.useEffect(() => {
|
||||
getSkin().then(async root => {
|
||||
// Execute scripts
|
||||
|
|
@ -372,7 +376,7 @@ function App() {
|
|||
}
|
||||
});
|
||||
|
||||
setData(root);
|
||||
dispatch(Actions.setMakiTree(root));
|
||||
});
|
||||
}, []);
|
||||
if (data == null) {
|
||||
|
|
|
|||
5
modern/src/Selectors.ts
Normal file
5
modern/src/Selectors.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { ModernAppState, MakiTree } from "./types";
|
||||
|
||||
export function getMakiTree(state: ModernAppState): MakiTree | null {
|
||||
return state.makiTree;
|
||||
}
|
||||
|
|
@ -1,13 +1,15 @@
|
|||
import { ModernAppState, ModernAction } from "./types";
|
||||
import { createStore } from "redux";
|
||||
|
||||
const defaultState = {};
|
||||
const defaultState = { makiTree: null };
|
||||
|
||||
function reducer(
|
||||
state: ModernAppState = defaultState,
|
||||
action: ModernAction
|
||||
): ModernAppState {
|
||||
switch (action.type) {
|
||||
case "SET_MAKI_TREE":
|
||||
return { ...state, makiTree: action.makiTree };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,2 +1,7 @@
|
|||
export type ModernAppState = {};
|
||||
export type ModernAction = { type: "INIT" };
|
||||
// TODO: Type the state tree
|
||||
export type MakiTree = any;
|
||||
|
||||
export type ModernAppState = {
|
||||
makiTree: MakiTree | null;
|
||||
};
|
||||
export type ModernAction = { type: "SET_MAKI_TREE"; makiTree: MakiTree };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue