mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-23 10:07:35 +00:00
Add unique ID to each node in the state tree
This commit is contained in:
parent
287f226d32
commit
0deca6f156
3 changed files with 28 additions and 2 deletions
|
|
@ -2,6 +2,7 @@ import { MakiTree, ModernAction, ModernStore, XmlTree } from "./types";
|
|||
import JSZip from "jszip";
|
||||
import * as Utils from "./utils";
|
||||
import initialize from "./initialize";
|
||||
import initializeStateTree from "./initializeStateTree";
|
||||
import { run } from "./maki-interpreter/virtualMachine";
|
||||
import System from "./runtime/System";
|
||||
import runtime from "./runtime";
|
||||
|
|
@ -10,8 +11,13 @@ export function setMakiTree(makiTree: MakiTree): ModernAction {
|
|||
return { type: "SET_MAKI_TREE", makiTree };
|
||||
}
|
||||
|
||||
export function setXmlTree(xmlTree: XmlTree): ModernAction {
|
||||
return { type: "SET_XML_TREE", xmlTree };
|
||||
export function setXmlTree(xmlTree: XmlTree) {
|
||||
return async dispatch => {
|
||||
dispatch({
|
||||
type: "SET_XML_TREE",
|
||||
xmlTree: await initializeStateTree(xmlTree),
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function gotSkinUrl(skinUrl: string, store: ModernStore) {
|
||||
|
|
|
|||
15
modern/src/initializeStateTree.ts
Normal file
15
modern/src/initializeStateTree.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { XmlTree } from "./types";
|
||||
import * as Utils from "./utils";
|
||||
|
||||
function mapTree(node, cb) {
|
||||
const children = node.children || [];
|
||||
return cb({ ...node, children: children.map(child => mapTree(child, cb)) });
|
||||
}
|
||||
|
||||
export default async function initializeStateTree(
|
||||
xmlTree: XmlTree
|
||||
): Promise<XmlTree> {
|
||||
return mapTree(xmlTree, node => {
|
||||
return { ...node, uid: Utils.getId() };
|
||||
});
|
||||
}
|
||||
|
|
@ -1,5 +1,10 @@
|
|||
import { xml2js } from "xml-js";
|
||||
|
||||
let i = 0;
|
||||
export function getId() {
|
||||
return i++;
|
||||
}
|
||||
|
||||
export function isPromise(obj) {
|
||||
return obj && typeof obj.then === "function";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue