From e007718eaa91c2757bda2b24b7837508379c68f9 Mon Sep 17 00:00:00 2001 From: moajo Date: Fri, 10 Feb 2017 18:30:19 +0900 Subject: [PATCH 01/11] v0.14.4-beta7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a08bd7815..982a868e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "grimoirejs", - "version": "0.14.4-beta6", + "version": "0.14.4-beta7", "description": "A service-oriented WebGL framework.", "main": "./ref/index.js", "typings": "./ref/index.d.ts", From f1a2f10907e1dfba838ccc0de80d68f1b280a550 Mon Sep 17 00:00:00 2001 From: moajo Date: Fri, 10 Feb 2017 18:32:23 +0900 Subject: [PATCH 02/11] fix componentConverter bug. --- src/Base/NSIdentity.ts | 5 +++++ src/Converters/ComponentConverter.ts | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Base/NSIdentity.ts b/src/Base/NSIdentity.ts index 967d5019d..01041c372 100644 --- a/src/Base/NSIdentity.ts +++ b/src/Base/NSIdentity.ts @@ -112,6 +112,11 @@ class NSIdentity { return name; } + + public toString(): string { + return this.fqn; + } + private constructor(ns: string, name: string) { this._ns = ns.toUpperCase(); this._name = name; diff --git a/src/Converters/ComponentConverter.ts b/src/Converters/ComponentConverter.ts index 4c1a60d18..a7e56d9c3 100644 --- a/src/Converters/ComponentConverter.ts +++ b/src/Converters/ComponentConverter.ts @@ -1,3 +1,4 @@ +import Ensure from "../Base/Ensure"; import Component from "../Node/Component"; import GomlNode from "../Node/GomlNode"; import Attribute from "../Node/Attribute"; @@ -25,7 +26,7 @@ export default { if (val instanceof GomlNode) { return val.getComponent(attr.declaration["target"]); } else if (val instanceof Component) { - if (val.name === attr.declaration["target"]) { + if (val.name.fqn === Ensure.tobeNSIdentity(attr.declaration["target"]).fqn) { return val; } else { throw new Error(`Specified component must be ${attr.declaration["target"]}`); From efe2d4780527914a8357f40567a4c1bbd95dae33 Mon Sep 17 00:00:00 2001 From: moajo Date: Mon, 13 Feb 2017 15:38:05 +0900 Subject: [PATCH 03/11] rename Attribute#removeObserver to unwatch --- src/Node/Attribute.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Node/Attribute.ts b/src/Node/Attribute.ts index bcd255582..20546ca08 100644 --- a/src/Node/Attribute.ts +++ b/src/Node/Attribute.ts @@ -141,7 +141,7 @@ export default class Attribute { * @param {Attribute} handler [description] * @return {[type]} [description] */ - public removeObserver(target: (newValue: any, oldValue: any, attr: Attribute) => void): void { + public unwatch(target: (newValue: any, oldValue: any, attr: Attribute) => void): void { const index = this._observers.findIndex(f => f === target); if (index < 0) { return; From c545f793fdbf6505e6e44bad4c5023ab86d5fbd2 Mon Sep 17 00:00:00 2001 From: moajo Date: Mon, 13 Feb 2017 16:22:09 +0900 Subject: [PATCH 04/11] =?UTF-8?q?add=20argument=20=E2=80=98ignoireActivene?= =?UTF-8?q?ss=E2=80=99=20to=20Attribute#watch.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Node/Attribute.ts | 39 +++++++++++++++++++++++++++++--------- test/Node/GomlNode2Test.js | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 9 deletions(-) diff --git a/src/Node/Attribute.ts b/src/Node/Attribute.ts index 20546ca08..4f6c4f2e2 100644 --- a/src/Node/Attribute.ts +++ b/src/Node/Attribute.ts @@ -50,6 +50,7 @@ export default class Attribute { * List of functions that is listening changing values. */ private _observers: ((newValue: any, oldValue: any, attr: Attribute) => void)[] = []; + private _ignoireActivenessObservers: ((newValue: any, oldValue: any, attr: Attribute) => void)[] = []; /** * Goml tree interface which contains the component this attribute bound to. @@ -129,10 +130,14 @@ export default class Attribute { * @param {(attr: Attribute) => void} handler handler the handler you want to add. * @param {boolean = false} callFirst whether that handler should be called first time. */ - public watch(watcher: (newValue: any, oldValue: any, attr: Attribute) => void, immedateCalls = false): void { - this._observers.push(watcher); + public watch(watcher: (newValue: any, oldValue: any, attr: Attribute) => void, immedateCalls = false, ignoireActiveness = false): void { + if (ignoireActiveness) { + this._ignoireActivenessObservers.push(watcher); + } else { + this._observers.push(watcher); + } if (immedateCalls) { - watcher(this.Value, undefined, this); + watcher(this.Value, void 0, this); } } @@ -142,11 +147,16 @@ export default class Attribute { * @return {[type]} [description] */ public unwatch(target: (newValue: any, oldValue: any, attr: Attribute) => void): void { - const index = this._observers.findIndex(f => f === target); - if (index < 0) { + let index = this._observers.findIndex(f => f === target); + if (index >= 0) { + this._observers.splice(index, 1); + return; + } + index = this._ignoireActivenessObservers.findIndex(f => f === target); + if (index >= 0) { + this._ignoireActivenessObservers.splice(index, 1); return; } - this._observers.splice(index, 1); } /** @@ -212,11 +222,22 @@ export default class Attribute { private _notifyChange(newValue: any): void { if (!this.component.isActive) { - return; + if (this._ignoireActivenessObservers.length === 0) { + return; + } + const lastvalue = this._lastValuete; + const convertedNewValue = this._valuate(newValue); + this._ignoireActivenessObservers.forEach((watcher) => { + watcher(convertedNewValue, lastvalue, this); + }); } const lastvalue = this._lastValuete; - this._observers.forEach((handler) => { - handler(this.converter.convert(newValue, this), lastvalue, this); + const convertedNewValue = this._valuate(newValue); + this._observers.forEach((watcher) => { + watcher(convertedNewValue, lastvalue, this); + }); + this._ignoireActivenessObservers.forEach((watcher) => { + watcher(convertedNewValue, lastvalue, this); }); } } diff --git a/test/Node/GomlNode2Test.js b/test/Node/GomlNode2Test.js index 4fc9c6835..6035770cc 100644 --- a/test/Node/GomlNode2Test.js +++ b/test/Node/GomlNode2Test.js @@ -133,6 +133,45 @@ test('Nodes should be mounted after loading', (t) => { t.truthy(n.mounted); }); }); +test('attribute default value work correctly1', (t) => { + t.truthy(rootNode.getAttribute("id") !== void 0); + t.truthy(rootNode.getAttribute("id") === null); +}); + +test('attribute watch should work correctly', (t) => { + const idAttr = rootNode.getAttributeRaw("id"); + const spy = sinon.spy(); + + const watcher = (newValue, oldValue, attr) => { + // spy("watch", { newValue: newValue, oldValue: oldValue, attr: attr }); + spy(newValue); + }; + idAttr.watch(watcher); + idAttr.Value = "id"; + t.truthy(spy.getCall(0).args[0] === "id"); + + spy.reset(); + rootNode.enabled = false; + idAttr.Value = "id"; + sinon.assert.notCalled(spy); +}); +test('attribute watch should work correctly2', (t) => { + const idAttr = rootNode.getAttributeRaw("id"); + const spy = sinon.spy(); + const watcher = (newValue, oldValue, attr) => { + // spy("watch", { newValue: newValue, oldValue: oldValue, attr: attr }); + spy(newValue); + }; + idAttr.watch(watcher); + idAttr.unwatch(watcher); + idAttr.Value = "id"; + sinon.assert.notCalled(spy); + + idAttr.watch(watcher, false, true); + rootNode.enabled = false; + idAttr.Value = "idid"; + t.truthy(spy.getCall(0).args[0] === "idid"); +}); test('Broadcast message should call correct order', (t) => { rootNode.broadcastMessage("onTest"); From 30ac3d9873e3bb3cdcff6f640d022b3f9d49c2f3 Mon Sep 17 00:00:00 2001 From: moajo Date: Mon, 13 Feb 2017 17:04:10 +0900 Subject: [PATCH 05/11] fix: fix bug:GomlNode#enabled not works correctly. --- src/Components/GrimoireComponent.ts | 8 ++-- test/Node/GomlNode2Test.js | 64 ++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/src/Components/GrimoireComponent.ts b/src/Components/GrimoireComponent.ts index 6d4e440b1..623430f38 100644 --- a/src/Components/GrimoireComponent.ts +++ b/src/Components/GrimoireComponent.ts @@ -24,17 +24,17 @@ class GrimoireComponent extends Component { this.node.resolveAttributesValue(); this.getAttributeRaw("id").watch((attr) => { this.node.element.id = attr ? attr : ""; - }, true); + }, true, true); this.getAttributeRaw("class").watch((attr) => { this.node.element.className = Array.isArray(attr) ? attr.join(" ") : ""; - }, true); + }, true, true); this.getAttributeRaw("enabled").watch(attr => { this.node["_enabled"] = attr; const p = this.node.parent; this.node.notifyActivenessUpdate(p ? p.isActive && this.node.enabled : this.node.enabled); - }); + }, false, true); this.node["_enabled"] = this.getAttribute("enabled"); - this.node["_isActive"] = this.node.parent ? this.node.parent.isActive && this.enabled : this.enabled; + this.node["_isActive"] = this.node.parent ? this.node.parent.isActive && this.node.enabled : this.node.enabled; } } diff --git a/test/Node/GomlNode2Test.js b/test/Node/GomlNode2Test.js index 6035770cc..247f388a0 100644 --- a/test/Node/GomlNode2Test.js +++ b/test/Node/GomlNode2Test.js @@ -173,15 +173,40 @@ test('attribute watch should work correctly2', (t) => { t.truthy(spy.getCall(0).args[0] === "idid"); }); +test('enabled should work correctly', (t) => { + const testNode3 = rootNode.children[0]; + const testNode2 = testNode3.children[0]; + t.truthy(rootNode.enabled); + t.truthy(rootNode.isActive); + t.truthy(!testNode3.enabled); + t.truthy(!testNode3.isActive); + t.truthy(testNode2.enabled); + t.truthy(!testNode2.isActive); + testNode3.enabled = true; + t.truthy(testNode3.enabled); + t.truthy(testNode3.isActive); + t.truthy(testNode2.enabled); + t.truthy(testNode2.isActive); + testNode2.enabled = false; + t.truthy(!testNode2.enabled); + t.truthy(!testNode2.isActive); + rootNode.enabled = false; + t.truthy(!rootNode.enabled); + t.truthy(!rootNode.isActive); + t.truthy(testNode3.enabled); + t.truthy(!testNode3.isActive); + t.truthy(!testNode2.enabled); + t.truthy(!testNode2.isActive); +}); + test('Broadcast message should call correct order', (t) => { - rootNode.broadcastMessage("onTest"); sinon.assert.callOrder(testComponent3Spy, testComponent2Spy, testComponentOptionalSpy, testComponent1Spy); }); test('Broadcast message with range should work correctly', (t) => { const testNode3 = rootNode.children[0]; - testNode3.enabled = true; resetSpies(); + testNode3.enabled = true; rootNode.broadcastMessage(1, "onTest"); sinon.assert.called(testComponent3Spy); sinon.assert.notCalled(testComponent2Spy); @@ -189,6 +214,41 @@ test('Broadcast message with range should work correctly', (t) => { sinon.assert.notCalled(testComponent1Spy); }); +test('Broadcast message with enabled should work correctly', (t) => { + const testNode3 = rootNode.children[0]; + const testNode2 = testNode3.children[0]; + + resetSpies(); + sinon.assert.notCalled(testComponent3Spy); + sinon.assert.notCalled(testComponent2Spy); + sinon.assert.notCalled(testComponentOptionalSpy); + sinon.assert.notCalled(testComponent1Spy); + + resetSpies(); + rootNode.broadcastMessage("onTest"); + sinon.assert.notCalled(testComponent3Spy); + sinon.assert.notCalled(testComponent2Spy); + sinon.assert.notCalled(testComponentOptionalSpy); + sinon.assert.notCalled(testComponent1Spy); + + resetSpies(); + testNode3.enabled = true; + testNode2.enabled = false; + rootNode.broadcastMessage("onTest"); + sinon.assert.called(testComponent3Spy); + sinon.assert.notCalled(testComponent2Spy); + sinon.assert.notCalled(testComponentOptionalSpy); + sinon.assert.called(testComponent1Spy); + + resetSpies(); + testNode2.enabled = true; + rootNode.broadcastMessage("onTest"); + sinon.assert.called(testComponent3Spy); + sinon.assert.called(testComponent2Spy); + sinon.assert.called(testComponentOptionalSpy); + sinon.assert.called(testComponent1Spy); +}); + test('SendMessage should call correct order', (t) => { const testNode2 = rootNode.children[0].children[0]; testNode2.sendMessage("onTest"); From 3ba903fc1b3780d65866bb5faef2fa6da944cf5d Mon Sep 17 00:00:00 2001 From: moajo Date: Mon, 13 Feb 2017 17:32:30 +0900 Subject: [PATCH 06/11] implement GomlNode#toString --- src/Node/GomlNode.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Node/GomlNode.ts b/src/Node/GomlNode.ts index 92e7f737b..8523ac0d1 100644 --- a/src/Node/GomlNode.ts +++ b/src/Node/GomlNode.ts @@ -627,6 +627,18 @@ class GomlNode extends EEObject { public watch(attrName: string | NSIdentity, watcher: ((newValue: any, oldValue: any, attr: Attribute) => void), immediate = false) { this._attributeManager.watch(attrName, watcher, immediate); } + public toString(): string { + let name = this.name.fqn; + let id = this.getAttribute("id"); + if (id !== null) { + name += ` id: ${id}`; + } + let classValue = this.getAttribute("id"); + if (classValue !== null) { + name += ` class: ${classValue}`; + } + return name; + } private _sendMessage(message: string, args?: any): void { if (this._messageCache[message] === void 0) { From 6d17af3eee0df5d45f1976a87dfd1696d015b41b Mon Sep 17 00:00:00 2001 From: moajo Date: Mon, 13 Feb 2017 17:51:35 +0900 Subject: [PATCH 07/11] implement error event --- src/GrimoireInterfaceImpl.ts | 3 ++- src/Node/GomlNode.ts | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/GrimoireInterfaceImpl.ts b/src/GrimoireInterfaceImpl.ts index 56a40ee44..cedef65a8 100644 --- a/src/GrimoireInterfaceImpl.ts +++ b/src/GrimoireInterfaceImpl.ts @@ -1,3 +1,4 @@ +import EEObject from "./Base/EEObject"; import IAttributeConverterDeclaration from "./Declaration/IAttributeConverterDeclaration"; import GomlLoader from "./Node/GomlLoader"; import EnumConverter from "./Converters/EnumConverter"; @@ -27,7 +28,7 @@ import NSDictionary from "./Base/NSDictionary"; import Ensure from "./Base/Ensure"; -export default class GrimoireInterfaceImpl { +export default class GrimoireInterfaceImpl extends EEObject { public nodeDeclarations: NSDictionary = new NSDictionary(); diff --git a/src/Node/GomlNode.ts b/src/Node/GomlNode.ts index 8523ac0d1..24befacac 100644 --- a/src/Node/GomlNode.ts +++ b/src/Node/GomlNode.ts @@ -695,7 +695,23 @@ class GomlNode extends EEObject { } let method = targetComponent[message]; if (typeof method === "function") { - method(args); + try { + method(args); + } catch (e) { + const errorHandler = { + node: this, + component: targetComponent, + message: message, + handled: false + }; + this.emit("error", errorHandler); + if (!errorHandler.handled) { + GrimoireInterface.emit("error", errorHandler); + if (!errorHandler.handled) { + throw e; + } + } + } return true; } return false; From 1e838f8a01d8b15b1a47f7548d9faecf27a39873 Mon Sep 17 00:00:00 2001 From: moajo Date: Mon, 13 Feb 2017 18:40:21 +0900 Subject: [PATCH 08/11] change GomlNode#remove. --- src/Node/GomlNode.ts | 3 ++- test/Interfaces/NodeInterfaceTest.js | 6 +++--- test/Node/GomlNode2Test.js | 4 ---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Node/GomlNode.ts b/src/Node/GomlNode.ts index 24befacac..cd291a21e 100644 --- a/src/Node/GomlNode.ts +++ b/src/Node/GomlNode.ts @@ -198,6 +198,8 @@ class GomlNode extends EEObject { this.children.forEach((c) => { c.remove(); }); + this._sendMessageForced("$$dispose"); + this.removeAllListeners(); GrimoireInterface.nodeDictionary[this.id] = null; if (this._parent) { this._parent.detachChild(this); @@ -207,7 +209,6 @@ class GomlNode extends EEObject { this.element.parentNode.removeChild(this.element); } } - this._sendMessageForced("$$dispose"); this._deleted = true; } diff --git a/test/Interfaces/NodeInterfaceTest.js b/test/Interfaces/NodeInterfaceTest.js index fbbc59b4a..29ed17896 100644 --- a/test/Interfaces/NodeInterfaceTest.js +++ b/test/Interfaces/NodeInterfaceTest.js @@ -66,7 +66,6 @@ test.beforeEach(async() => { GrimoireInterface.clear(); const parser = new DOMParser(); let a = readFile("../../test/Node/_TestResource/GomlNodeTest_Case1.html"); - // console.log(a); const htmlDoc = parser.parseFromString(a, "text/html"); global.document = htmlDoc; global.document.querySelectorAll = function (selector) { @@ -96,8 +95,9 @@ test.beforeEach(async() => { }); test('count first single.', (t) => { - // const ni = GrimoireInterface("*")("*"); - // console.log(GrimoireInterface("*")("*").nodes) + console.log(GrimoireInterface("*").rootNodes[0].name); + const ni = GrimoireInterface("script")("goml"); + console.log(ni.nodes) // t.truthy(ni.count() === 1); // t.truthy(ni.first()); t.truthy(true); diff --git a/test/Node/GomlNode2Test.js b/test/Node/GomlNode2Test.js index 247f388a0..83ecbc6b0 100644 --- a/test/Node/GomlNode2Test.js +++ b/test/Node/GomlNode2Test.js @@ -376,7 +376,3 @@ test('null should be "" as id and classname', (t) => { t.truthy(child.element.className === ""); t.truthy(child.getComponent("GrimoireComponent").getAttribute("class") === null); }); - -// test("getComponentsInChildren",t=>{ -// GrimoireInterface("") -// }); From 0190032fa0413110b394e13ccffb9f3ac0d391bb Mon Sep 17 00:00:00 2001 From: moajo Date: Tue, 14 Feb 2017 14:43:49 +0900 Subject: [PATCH 09/11] fix error log in XMLReader. --- src/Base/XMLReader.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Base/XMLReader.ts b/src/Base/XMLReader.ts index 40db9d912..e8df3c3f5 100644 --- a/src/Base/XMLReader.ts +++ b/src/Base/XMLReader.ts @@ -27,7 +27,8 @@ class XMLReader { // throw new Error("Error parsing XML"); // } if (!parsed || parsed.getElementsByTagName("parsererror").length > 0) { - throw new Error("Error parsing XML"); + const err = new XMLSerializer().serializeToString(parsed); + throw new Error(`Error parsing XML: ${err}`); } if (rootElementName) { if (parsed.documentElement.tagName.toUpperCase() !== rootElementName.toUpperCase()) { From dedcd730d89af5ea1cda691327df83e018700981 Mon Sep 17 00:00:00 2001 From: Kakeru Ishii Date: Fri, 24 Feb 2017 18:05:13 +0900 Subject: [PATCH 10/11] fix: NumberConverter now accept an array sized 1 --- src/Converters/NumberConverter.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Converters/NumberConverter.ts b/src/Converters/NumberConverter.ts index 8612e7a42..5521afb97 100644 --- a/src/Converters/NumberConverter.ts +++ b/src/Converters/NumberConverter.ts @@ -10,5 +10,7 @@ export default function NumberConverter(val: any): number { return Number.parseFloat(val); } else if (val === null) { return null; + } else if (Array.isArray(val) && val.length === 1) { + return val[0]; } } From 9557efed3dd432ee0b8aa238b3f7d05f3fe64695 Mon Sep 17 00:00:00 2001 From: Kakeru Ishii Date: Tue, 21 Mar 2017 09:48:07 +0900 Subject: [PATCH 11/11] chore: fix contributing md --- CONTRIBUTING.md | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 780500b74..b50b17149 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -# Guideline for contribution[WIP] +# Guideline for contribution ## Got a questions or problem? @@ -22,6 +22,25 @@ This is including a lot of stuff to do, we need contributors. Even if you correc Reducing works we need to do manually is very important. Please read this guideline for keeping clean repository and keeping developing environment efficiently. +### Build library + +You need to use npm to setup project build environment.(You can use yarn also) + +```sh +$ git clone . +$ npm install +$ npm start +``` + +`npm start` trigger watch task to rebuild when you changed the codes in `src` folder. +This command will change `register/index.js` only. + +If you need to build with all build configurations, you can use `npm run build -- --env.prod` to generate all codes. + +`npm test` will execute unit testing included in `test` folder. + +If you need to use with the other plugins, `npm link` would be useful to use generated new codes. + ### Coding rule Most of the coding rules are checked with `TSLint`. You can run `npm run lint` to check whether your code is fitting to coding rule. @@ -43,9 +62,15 @@ Protected method name must begin with two `__`, and following characters are sam ### Commit message guideline -Currently the version of this package is managed by `semantic-release`. +The version of this package uses `semantic-release`. To generate changelog and release new version automatically, please follow this rule. +### When the commit is only changing comments(Anything no effect for logics) + +``` +chore: COMMIT MESSAGE HERE +``` + #### When the commit is bug fix,refactor or chore (Anything no effect for API). ```