From 1f3cb76212e3d52c642091fa2d8e0b8a81ec4cbf Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Thu, 19 Sep 2019 07:11:20 -0700 Subject: [PATCH] Remove the Redux store from Maki objects --- modern/src/MakiSelectors.ts | 44 ------------------ modern/src/initialize.js | 69 ++++++++++++----------------- modern/src/runtime/AnimatedLayer.ts | 4 +- modern/src/runtime/GuiObject.ts | 9 +--- modern/src/runtime/MakiObject.ts | 11 +---- modern/src/runtime/System.ts | 5 ++- modern/src/runtime/Timer.ts | 4 +- 7 files changed, 40 insertions(+), 106 deletions(-) delete mode 100644 modern/src/MakiSelectors.ts diff --git a/modern/src/MakiSelectors.ts b/modern/src/MakiSelectors.ts deleted file mode 100644 index 2e0181f2..00000000 --- a/modern/src/MakiSelectors.ts +++ /dev/null @@ -1,44 +0,0 @@ -import * as Utils from "./utils"; -import { ModernAppState, XmlNode } from "./types"; - -function findNodeByUid(uid: number) { - // TODO: Do some clever caching here. - return (state: ModernAppState): XmlNode => { - return Utils.findInTree( - state.modernSkin.xmlTree, - (node: XmlNode): boolean => { - return node.uid === uid; - } - ); - }; -} - -export function getTop(uid: number) { - const findNodeInState = findNodeByUid(uid); - return (state: ModernAppState): number => { - const node = findNodeInState(state); - return Number(node.attributes.y) || 0; - }; -} - -export function getPathToUid(uid: number) { - return (state: ModernAppState): number[] | null => { - return Utils.findPathToNode( - state.modernSkin.xmlTree, - node => node.uid === uid - ); - }; -} - -export function getNodeAtPath(path: number[]) { - return (state: ModernAppState): XmlNode | null => { - let node = state.modernSkin.xmlTree; - path.forEach(offset => { - if (node == null) { - return null; - } - node = node.children[offset]; - }); - return node; - }; -} diff --git a/modern/src/initialize.js b/modern/src/initialize.js index d09c6a2c..e5dfa5c9 100644 --- a/modern/src/initialize.js +++ b/modern/src/initialize.js @@ -61,12 +61,10 @@ function imageAttributesFromNode(node) { } } -const noop = (node, parent, zip, store) => - new GuiObject(node, parent, undefined, store); +const noop = (node, parent, zip) => new GuiObject(node, parent, undefined); const parsers = { - groupdef: (node, parent, zip, store) => - new JsGroupDef(node, parent, undefined, store), + groupdef: (node, parent, zip) => new JsGroupDef(node, parent, undefined), skininfo: noop, guiobject: noop, version: noop, @@ -77,49 +75,38 @@ const parsers = { email: noop, homepage: noop, screenshot: noop, - container: (node, parent, zip, store) => - new Container(node, parent, undefined, store), + container: (node, parent, zip) => new Container(node, parent, undefined), scripts: noop, - gammaset: (node, parent, zip, store) => - new JsGammaSet(node, parent, undefined, store), + gammaset: (node, parent, zip) => new JsGammaSet(node, parent, undefined), color: noop, - layer: (node, parent, zip, store) => - new Layer(node, parent, undefined, store), + layer: (node, parent, zip) => new Layer(node, parent, undefined), layoutstatus: noop, hideobject: noop, - button: (node, parent, zip, store) => - new Button(node, parent, undefined, store), - group: (node, parent, zip, store) => - new Group(node, parent, undefined, store), - layout: (node, parent, zip, store) => - new Layout(node, parent, undefined, store), + button: (node, parent, zip) => new Button(node, parent, undefined), + group: (node, parent, zip) => new Group(node, parent, undefined), + layout: (node, parent, zip) => new Layout(node, parent, undefined), sendparams: noop, - elements: (node, parent, zip, store) => - new JsElements(node, parent, undefined, store), + elements: (node, parent, zip) => new JsElements(node, parent, undefined), bitmap: noop, - eqvis: (node, parent, zip, store) => - new EqVis(node, parent, undefined, store), - slider: (node, parent, zip, store) => - new Slider(node, parent, undefined, store), + eqvis: (node, parent, zip) => new EqVis(node, parent, undefined), + slider: (node, parent, zip) => new Slider(node, parent, undefined), gammagroup: noop, - truetypefont: async (node, parent, zip, store) => { + truetypefont: async (node, parent, zip) => { const { file } = node.attributes; const font = Utils.getCaseInsensitveFile(zip, file); const fontBlob = await font.async("blob"); const fontUrl = await Utils.getUrlFromBlob(fontBlob); const fontFamily = `font-${Utils.getId()}-${file.replace(/\./, "_")}`; await Utils.loadFont(fontUrl, fontFamily); - return new MakiObject(node, parent, { fontFamily }, store); + return new MakiObject(node, parent, { fontFamily }); }, - component: (node, parent, zip, store) => - new Component(node, parent, undefined, store), - text: (node, parent, zip, store) => new Text(node, parent, undefined, store), - togglebutton: (node, parent, zip, store) => - new ToggleButton(node, parent, undefined, store), - status: (node, parent, zip, store) => - new Status(node, parent, undefined, store), + component: (node, parent, zip) => new Component(node, parent, undefined), + text: (node, parent, zip) => new Text(node, parent, undefined), + togglebutton: (node, parent, zip) => + new ToggleButton(node, parent, undefined), + status: (node, parent, zip) => new Status(node, parent, undefined), bitmapfont: noop, - vis: (node, parent, zip, store) => new Vis(node, parent, undefined, store), + vis: (node, parent, zip) => new Vis(node, parent, undefined), "wasabi:titlebar": noop, "colorthemes:list": noop, "wasabi:standardframe:status": noop, @@ -131,8 +118,8 @@ const parsers = { elementalias: noop, grid: noop, rect: noop, - animatedlayer: (node, parent, zip, store) => - new AnimatedLayer(node, parent, undefined, store), + animatedlayer: (node, parent, zip) => + new AnimatedLayer(node, parent, undefined), nstatesbutton: noop, songticker: noop, menu: noop, @@ -141,7 +128,7 @@ const parsers = { script: noop, }; -async function parseChildren(node, children, zip, store) { +async function parseChildren(node, children, zip) { if (node.type === "comment") { return; } @@ -157,7 +144,7 @@ async function parseChildren(node, children, zip, store) { } if (child.type === "text") { // TODO: Handle text - return new MakiObject({ ...child }, node, undefined, store); + return new MakiObject({ ...child }, node, undefined); } if (child.name == null) { console.error(child); @@ -174,10 +161,10 @@ async function parseChildren(node, children, zip, store) { console.warn(`Missing parser in initialize for ${childName}`); childParser = noop; } - const parsedChild = await childParser(child, node, zip, store); + const parsedChild = await childParser(child, node, zip); child.maki = parsedChild; if (child.children != null && child.children.length > 0) { - await parseChildren(parsedChild, child.children, zip, store); + await parseChildren(parsedChild, child.children, zip); } return parsedChild; }) @@ -265,11 +252,11 @@ async function applyGroupDefs(root) { }); } -async function initialize(zip, skinXml, store) { +async function initialize(zip, skinXml) { const xmlRoot = skinXml.children[0]; await applyImageLookups(xmlRoot, zip); - const root = new JsWinampAbstractionLayer(xmlRoot, null, undefined, store); - await parseChildren(root, xmlRoot.children, zip, store); + const root = new JsWinampAbstractionLayer(xmlRoot, null, undefined); + await parseChildren(root, xmlRoot.children, zip); await applyGroupDefs(root); return root; } diff --git a/modern/src/runtime/AnimatedLayer.ts b/modern/src/runtime/AnimatedLayer.ts index 9f6eabda..d24dd78e 100644 --- a/modern/src/runtime/AnimatedLayer.ts +++ b/modern/src/runtime/AnimatedLayer.ts @@ -6,8 +6,8 @@ class AnimatedLayer extends Layer { _frameNum: number; _animationStartTime: number; - constructor(node, parent, annotations, store) { - super(node, parent, annotations, store); + constructor(node, parent, annotations) { + super(node, parent, annotations); this._setAttributeDefaults(); this._convertAttributeTypes(); diff --git a/modern/src/runtime/GuiObject.ts b/modern/src/runtime/GuiObject.ts index efbe07c1..ee209110 100644 --- a/modern/src/runtime/GuiObject.ts +++ b/modern/src/runtime/GuiObject.ts @@ -33,13 +33,8 @@ class GuiObject extends MakiObject { _transitionParams: TransitionParams; _targetAnimationStartTime: number; _targetAnimationCancelID: number | null; - constructor( - node: XmlNode, - parent: MakiObject, - annotations: Object = {}, - store: ModernStore - ) { - super(node, parent, annotations, store); + constructor(node: XmlNode, parent: MakiObject, annotations: Object = {}) { + super(node, parent, annotations); this._setAttributeDefaults(); this._convertAttributeTypes(); diff --git a/modern/src/runtime/MakiObject.ts b/modern/src/runtime/MakiObject.ts index 3a7843e1..17b3e275 100644 --- a/modern/src/runtime/MakiObject.ts +++ b/modern/src/runtime/MakiObject.ts @@ -1,12 +1,11 @@ import Emitter from "../Emitter"; import * as Utils from "../utils"; -import { ModernStore, XmlNode } from "../types"; +import { XmlNode } from "../types"; class MakiObject { _node: XmlNode; name: string; _uid: number; - _store: ModernStore; // TODO: This should really just be `string | undefined` and we should handle // type conversion differently. Having one type that holds both the pre and // post type coerced values is too confusing. @@ -16,14 +15,8 @@ class MakiObject { children: MakiObject[]; js_annotations: Object; - constructor( - node: XmlNode, - parent: MakiObject, - annotations: Object = {}, - store: ModernStore - ) { + constructor(node: XmlNode, parent: MakiObject, annotations: Object = {}) { this._node = node; - this._store = store; if (node) { this._uid = node.uid; this.attributes = node.attributes || {}; diff --git a/modern/src/runtime/System.ts b/modern/src/runtime/System.ts index 7f58fb7c..bc8fed79 100644 --- a/modern/src/runtime/System.ts +++ b/modern/src/runtime/System.ts @@ -7,14 +7,17 @@ import { } from "../utils"; import * as Actions from "../Actions"; import * as Selectors from "../Selectors"; +import { ModernStore } from "../types"; class System extends MakiObject { scriptGroup: Group; root: MakiObject; + _store: ModernStore; _privateInt: Map>; _privateString: Map>; constructor(scriptGroup, store) { - super(null, null, {}, store); + super(null, null, {}); + this._store = store; this.scriptGroup = scriptGroup == null ? new Group() : scriptGroup; this.root = scriptGroup; diff --git a/modern/src/runtime/Timer.ts b/modern/src/runtime/Timer.ts index e58efeea..cb4ad6da 100644 --- a/modern/src/runtime/Timer.ts +++ b/modern/src/runtime/Timer.ts @@ -6,8 +6,8 @@ class Timer extends MakiObject { _animationStartTime: number; _animationCancelID: number; - constructor(node, parent, annotations, store) { - super(node, parent, annotations, store); + constructor(node, parent, annotations) { + super(node, parent, annotations); this._speed = 200; this._animationStartTime = 0;