mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-23 10:07:35 +00:00
Share uids between maki objects and state tree
This commit is contained in:
parent
66e5091811
commit
efe13aac32
4 changed files with 17 additions and 18 deletions
|
|
@ -35,10 +35,13 @@ export function gotSkinBlob(blob: Blob, store: ModernStore) {
|
|||
|
||||
function gotSkinZip(zip: JSZip, store: ModernStore) {
|
||||
return async dispatch => {
|
||||
const xmlTree = await Utils.inlineIncludes(
|
||||
const rawXmlTree = await Utils.inlineIncludes(
|
||||
await Utils.readXml(zip, "skin.xml"),
|
||||
zip
|
||||
);
|
||||
const xmlTree = Utils.mapTree(rawXmlTree, node => {
|
||||
return { ...node, uid: Utils.getId() };
|
||||
});
|
||||
|
||||
dispatch(setXmlTree(xmlTree));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,7 @@
|
|||
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() };
|
||||
});
|
||||
return xmlTree;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,15 @@
|
|||
import Emitter from "../Emitter";
|
||||
import {
|
||||
findElementById,
|
||||
findGroupDefById,
|
||||
unimplementedWarning,
|
||||
} from "../utils";
|
||||
import * as Utils from "../utils";
|
||||
|
||||
class MakiObject {
|
||||
constructor(node, parent, annotations = {}, store) {
|
||||
this._store = store;
|
||||
if (node) {
|
||||
this._uid = node.uid;
|
||||
this.attributes = node.attributes || {};
|
||||
this.name = node.name;
|
||||
} else {
|
||||
this._uid = Utils.getId();
|
||||
// When dynamically creating an object with `new` we have no underlying node
|
||||
this.attributes = {};
|
||||
this.name = this.getclassname().toLowerCase();
|
||||
|
|
@ -56,7 +54,7 @@ class MakiObject {
|
|||
}
|
||||
|
||||
js_imageLookup(id) {
|
||||
const element = findElementById(this, id);
|
||||
const element = Utils.findElementById(this, id);
|
||||
if (element) {
|
||||
return element.js_annotations;
|
||||
}
|
||||
|
|
@ -65,7 +63,7 @@ class MakiObject {
|
|||
}
|
||||
|
||||
js_groupdefLookup(id) {
|
||||
const groupdef = findGroupDefById(this, id);
|
||||
const groupdef = Utils.findGroupDefById(this, id);
|
||||
if (groupdef) {
|
||||
return groupdef;
|
||||
}
|
||||
|
|
@ -91,7 +89,7 @@ class MakiObject {
|
|||
}
|
||||
|
||||
onnotify(command, param, a, b) {
|
||||
unimplementedWarning("onnotify");
|
||||
Utils.unimplementedWarning("onnotify");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,12 @@ export function getId() {
|
|||
return i++;
|
||||
}
|
||||
|
||||
// Depth-first tree map
|
||||
export function mapTree(node, cb) {
|
||||
const children = node.children || [];
|
||||
return cb({ ...node, children: children.map(child => mapTree(child, cb)) });
|
||||
}
|
||||
|
||||
export function isPromise(obj) {
|
||||
return obj && typeof obj.then === "function";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue