Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:GrimoireGL/GrimoireJS into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
kyasbal committed Jan 24, 2018
2 parents 0836ef6 + 652624e commit df6a281
Show file tree
Hide file tree
Showing 49 changed files with 1,307 additions and 623 deletions.
2 changes: 1 addition & 1 deletion common
Submodule common updated 2 files
+1 −1 debug.js
+0 −1 tslint.json
26 changes: 12 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "grimoirejs",
"version": "1.0.0",
"version": "1.0.9-beta18",
"description": "A service-oriented WebGL framework.",
"main": "./ref/index.js",
"typings": "./ref/index.d.ts",
Expand All @@ -16,8 +16,8 @@
"eventemitter3": "^3.0.0"
},
"devDependencies": {
"@types/sinon": "^2.3.5",
"ava": "^0.22.0",
"@types/sinon": "^4.1.2",
"ava": "^0.24.0",
"babel-cli": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-transform-runtime": "^6.23.0",
Expand All @@ -27,28 +27,26 @@
"babel-register": "^6.26.0",
"condition-circle": "^2.0.1",
"cpx": "^1.5.0",
"grimoirejs-cauldron": "beta",
"grimoirejs-cauldron": "^4.1.5-beta2",
"jsdom": "^11.3.0",
"lodash": "^4.17.2",
"nyc": "^11.4.1",
"proxyquire": "^1.7.11",
"regenerator-runtime": "^0.11.0",
"remap-istanbul": "^0.9.5",
"semantic-release": "^7.0.2",
"sinon": "^4.1.3",
"remap-istanbul": "^0.10.0",
"semantic-release": "^11.0.2",
"sinon": "^4.1.5",
"trash-cli": "^1.4.0",
"ts-loader": "^3.2.0",
"tslint": "^5.8.0",
"typedoc": "^0.8.0",
"tslint": "^5.9.1",
"typedoc": "^0.9.0",
"typedoc-md-theme": "^1.0.1",
"typescript": "^2.6.1",
"typescript-awaiter": "^1.0.0",
"webpack": "^3.8.1",
"webpack-shell-plugin": "^0.5.0",
"xhr-mock": "^1.9.1",
"xhr-mock": "^2.0.3",
"xmldom": "^0.1.27",
"xmlserializer": "^0.6.0",
"yargs": "^8.0.2"
"xmlserializer": "^0.6.1"
},
"repository": "http://github.com/GrimoireGL/GrimoireJS",
"scripts": {
Expand Down Expand Up @@ -91,4 +89,4 @@
"**/src/**/*"
]
}
}
}
28 changes: 17 additions & 11 deletions src/Base/EEObject.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { EventEmitter, ListenerFn } from "eventemitter3";
import { EventID } from "../Core/Constants";
import IDObject from "./IDObject";

/**
* EventEmitterをmixinしたIDObject
*/
class EEObject extends IDObject implements EventEmitter {
class EEObject extends IDObject {
/**
* Return an array listing the events for which the emitter has registered
* listeners.
Expand All @@ -21,16 +22,6 @@ class EEObject extends IDObject implements EventEmitter {
*/
public listenerCount: (event: string | symbol) => number;

/**
* Calls each of the listeners registered for a given event.
*/
public emit: (event: string | symbol, ...args: any[]) => boolean;

/**
* Add a listener for a given event.
*/
public on: (event: string | symbol, fn: ListenerFn, context?: any) => this;

/**
* add listener
*/
Expand Down Expand Up @@ -60,6 +51,21 @@ class EEObject extends IDObject implements EventEmitter {
super();
EventEmitter.call(this);
}

/**
* Calls each of the listeners registered for a given event.
*/
public emit<T>(event: EventID<T> | string | symbol, args: T): boolean {
return !!{ event, args };
}

/**
* Add a listener for a given event.
*/
public on<T= any>(event: EventID<T> | string | symbol, fn: (args: T) => void, context?: any): EEObject {
return { event, fn, context } as any;
}

}

function applyMixins(derivedCtor: any, baseCtors: any[]) {
Expand Down
5 changes: 1 addition & 4 deletions src/Component/GrimoireComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import StringConverter from "../Converter/StringConverter";
import Component from "../Core/Component";
import Identity from "../Core/Identity";
import Namespace from "../Core/Namespace";
import IAttributeConverterDeclaration from "../Interface/IAttributeConverterDeclaration";
import { __NAMESPACE__ } from "../metaInfo";

export { IAttributeConverterDeclaration };

/**
* Basic Component for all node.
*/
Expand Down Expand Up @@ -49,7 +46,7 @@ export default class GrimoireComponent extends Component {
node.element.className = Array.isArray(attr) ? attr.join(" ") : "";
}, true, true);
this.getAttributeRaw(GrimoireComponent.attributes.enabled)!.watch(attr => {
node["_enabled"] = attr;
node["_enabled"] = !!attr;
const p = node.parent;
node.notifyActivenessUpdate(p ? p.isActive && node.enabled : node.enabled);
}, false, true);
Expand Down
5 changes: 2 additions & 3 deletions src/Component/TemplateComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import StringConverter from "../Converter/StringConverter";
import Component from "../Core/Component";
import GomlNode from "../Core/GomlNode";
import GomlParser from "../Core/GomlParser";
import IAttributeConverterDeclaration from "../Interface/IAttributeConverterDeclaration";
import Identity from "../Core/Identity";
import { IConverterDeclaration, IStandardConverterDeclaration } from "../Interface/IAttributeConverterDeclaration";
import XMLHttpRequestAsync from "../Tool/XMLHttpRequestAsync";
import XMLReader from "../Tool/XMLReader";

export { IAttributeConverterDeclaration };

/**
* template component
* This component is intended to treat the structured node structure as a single node.
Expand Down
23 changes: 13 additions & 10 deletions src/Converter/ArrayConverter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Attribute from "../Core/Attribute";
import { StandardAttribute } from "../Core/Attribute";
import GrimoireInterface from "../Core/GrimoireInterface";

const splitter = " ";
Expand All @@ -12,13 +12,13 @@ const escape = "\\";
* 文字列が与えられたとき、*半角スペース*で区切られた文字列ごとに配列に分割して同様の処理を行います。
* ただし、`\`(バックスラッシュ)で*半角スペースをエスケープできます*
*/
export default {
export const ArrayConverter = {
name: "Array",
/**
* verify
* @param attr
*/
verify(attr: Attribute) {
verify(attr: StandardAttribute) {
if (!attr.declaration["type"]) {
throw new Error("Array converter needs to be specified type in attribute declaration.");
}
Expand All @@ -28,13 +28,14 @@ export default {
* @param val
* @param attr
*/
convert(val: any, attr: Attribute) {
const converter = GrimoireInterface.converters.get(attr.declaration["type"]);
if (!converter) {
throw new Error(`converter ${attr.declaration["type"]} is not registerd.`);
}
convert(val: any, attr: StandardAttribute) {

// const converter = GrimoireInterface.converters.get(attr.declaration["type"]);
// if (!converter) {
// throw new Error(`converter ${attr.declaration["type"]} is not registerd.`);
// }
if (Array.isArray(val)) {
return val.map(v => converter.convert(v, attr));
return val.map(v => StandardAttribute.convert(attr.declaration["type"], attr, v));
}
if (typeof val === "string") {
const ar = val.split(splitter);
Expand All @@ -50,8 +51,10 @@ export default {
}
}

return ar.map(v => converter.convert(v, attr));
return ar.map(v => StandardAttribute.convert(attr.declaration["type"], attr, v));
}
return null;
},
};

export default ArrayConverter;
10 changes: 7 additions & 3 deletions src/Converter/BooleanConverter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Identity from "../Core/Identity";
import Namespace from "../Core/Namespace";
import IAttributeConverterDeclaration from "../Interface/IAttributeConverterDeclaration";
import { IStandardConverterDeclaration } from "../Interface/IAttributeConverterDeclaration";
import { __NAMESPACE__ } from "../metaInfo";
import { Name } from "../Tool/Types";

export default {
export const BooleanConverter = {
name: Namespace.define(__NAMESPACE__).for("Boolean"),

/**
Expand All @@ -26,4 +28,6 @@ export default {
}
return undefined;
},
} as IAttributeConverterDeclaration<boolean>;
};

export default BooleanConverter;
23 changes: 16 additions & 7 deletions src/Converter/ComponentConverter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import Attribute from "../Core/Attribute";
import { StandardAttribute } from "../Core/Attribute";
import Component from "../Core/Component";
import GomlNode from "../Core/GomlNode";
import Ensure from "../Tool/Ensure";
import { Undef } from "../Tool/Types";

export interface IComponentConverter<T> {
name: "Component";
verify(attr: StandardAttribute): void;
convert(val: any, attr: StandardAttribute): Undef<T>;
}

export function getGenericComponentConverter<T>(): IComponentConverter<T> {
return ComponentConverter as IComponentConverter<T>;
}

/**
* コンポーネントのためのコンバータです。
* 属性宣言に`target`パラメータの指定が必要です。
Expand All @@ -12,14 +22,14 @@ import { Undef } from "../Tool/Types";
* `Component`に対しては、`target`パラメータと型が一致していればそのまま返します。そうでなければ、例外を投げます。
* 文字列の場合、ノードに対するクエリとして解釈され、取得されたノードに対して`getComponent`されます。
*/
export default {
export const ComponentConverter = {
name: "Component",

/**
* verify
* @param attr
*/
verify(attr: Attribute) {
verify(attr: StandardAttribute) {
if (!attr.declaration["target"]) {
throw new Error("Component converter require to be specified target");
}
Expand All @@ -29,10 +39,7 @@ export default {
* @param val
* @param attr
*/
convert(val: any, attr: Attribute): Undef<Component> {
if (val === null) {
return null;
}
convert(val: any, attr: StandardAttribute): Undef<Component> {
if (val instanceof GomlNode) {
return val.getComponent<Component>(attr.declaration["target"]);
} else if (val instanceof Component) {
Expand All @@ -50,3 +57,5 @@ export default {
}
},
};

export default ComponentConverter;
10 changes: 6 additions & 4 deletions src/Converter/EnumConverter.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import Attribute from "../Core/Attribute";
import {StandardAttribute} from "../Core/Attribute";
/**
* 列挙のためのコンバータ。
* 属性宣言に`table`パラメータが必要です。
* `table`パラメータは列挙する文字列から数値への連想配列です。
* 数値の場合、そのまま返します。
* 文字列の場合、テーブルの対応する値を返します。
*/
export default {
export const EnumConverter = {
name: "Enum",
/**
* verify
* @param attr
*/
verify(attr: Attribute) {
verify(attr: StandardAttribute) {
if (!attr.declaration["table"]) {
throw new Error("Enum converter needs to be specified table in attribute dictionary");
}
Expand All @@ -22,7 +22,7 @@ export default {
* @param val
* @param attr
*/
convert(val: any, attr: Attribute) {
convert(val: any, attr: StandardAttribute) {
if (val === null) {
return null;
}
Expand All @@ -38,3 +38,5 @@ export default {
}
},
};

export default EnumConverter;
6 changes: 4 additions & 2 deletions src/Converter/NumberConverter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Undef } from "../Tool/Types";
import Utility from "../Tool/Utility";
import * as Utility from "../Tool/Utility";

export default {
export const NumberConverter = {
name: "Number",
/**
* converter for number value.
Expand Down Expand Up @@ -31,3 +31,5 @@ export default {
return undefined;
},
};

export default NumberConverter;
4 changes: 3 additions & 1 deletion src/Converter/ObjectConverter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
export const ObjectConverter = {
name: "Object",
/**
* converter for object
Expand All @@ -10,3 +10,5 @@ export default {
return val;
},
};

export default ObjectConverter;
14 changes: 7 additions & 7 deletions src/Converter/StringConverter.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import Identity from "../Core/Identity";
import Namespace from "../Core/Namespace";
import IAttributeConverterDeclaration from "../Interface/IAttributeConverterDeclaration";
import { IStandardConverterDeclaration } from "../Interface/IAttributeConverterDeclaration";
import { __NAMESPACE__ } from "../metaInfo";
import { Undef } from "../Tool/Types";
import { Name, Undef } from "../Tool/Types";

export default {
export const StringConverter = {
name: Namespace.define(__NAMESPACE__).for("String"),
/**
* convert to string
* @param val
*/
convert(val: any): Undef<string> {
convert(val: any): string | undefined {
if (typeof val === "string") {
return val;
} else if (!val) {
return val;
} else if (typeof val.toString === "function") {
return val.toString();
}
return undefined;
},
} as IAttributeConverterDeclaration<string | null>;
};
export default StringConverter;
Loading

0 comments on commit df6a281

Please sign in to comment.