Skip to content

Commit

Permalink
addComponent will return correct type
Browse files Browse the repository at this point in the history
  • Loading branch information
kyasbal committed Jan 24, 2018
1 parent cf61a97 commit ab91d5e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "grimoirejs",
"version": "1.0.9-beta18",
"version": "1.0.9-beta23",
"description": "A service-oriented WebGL framework.",
"main": "./ref/index.js",
"typings": "./ref/index.d.ts",
Expand All @@ -27,7 +27,7 @@
"babel-register": "^6.26.0",
"condition-circle": "^2.0.1",
"cpx": "^1.5.0",
"grimoirejs-cauldron": "^4.1.6-beta",
"grimoirejs-cauldron": "^4.2.0-beta1",
"jsdom": "^11.3.0",
"lodash": "^4.17.2",
"nyc": "^11.4.1",
Expand Down Expand Up @@ -89,4 +89,4 @@
"**/src/**/*"
]
}
}
}
2 changes: 2 additions & 0 deletions src/Core/GomlNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@ export default class GomlNode extends EEObject {
* attach component to this node.
* @param {Component} component [description]
*/
public addComponent<T extends Component = Component>(component: (new () => T), attributes?: { [key: string]: any } | null, isDefaultComponent?: boolean): T;
public addComponent<T extends Component = Component>(component: Name, attributes?: { [key: string]: any } | null, isDefaultComponent?: boolean): T;
public addComponent(component: Name | (new () => Component), attributes?: { [key: string]: any } | null, isDefaultComponent = false): Component {
component = Ensure.tobeComponentIdentity(component);
const declaration = GrimoireInterface.componentDeclarations.get(component);
Expand Down
2 changes: 1 addition & 1 deletion src/Core/GrimoireInterfaceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default class GrimoireInterfaceImpl extends EEObject {
if (pathes.length === 1 || (pathes.length === 2 && pathes[1] === "ref")) {
const p = pathes[0];
if (p === "grimoirejs") {
return Environment.GrimoireInterface;
return requireDefault ? Environment.GrimoireInterface : { default: Environment.GrimoireInterface };
}
const obj = findLib(p, this.lib);
Utility.assert(!!obj, `invalid import path: ${path}`);
Expand Down
16 changes: 8 additions & 8 deletions test/Core/GrimoireInterfaceTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ TestEnvManager.init();

const tc1_html = fs.readFile("../_TestResource/GrimoireInterfaceTest_Case1.html");

test.beforeEach(async() => {
test.beforeEach(async () => {
GrimoireInterface.clear();
GrimoireInterface.resolvePlugins();
});
Expand Down Expand Up @@ -82,7 +82,7 @@ test("registerComponent works correctly", (t) => {
});
});

test("registerComponent by object works correctly", async(t) => {
test("registerComponent by object works correctly", async (t) => {
const defaultComponentCount = GrimoireInterface.componentDeclarations.toArray().length;
GrimoireInterface.registerComponent({
componentName: "Aaa",
Expand Down Expand Up @@ -151,7 +151,7 @@ test("registerComponent by object works correctly", async(t) => {
t.truthy((bbb2 as any).$test);
t.truthy((bbb2 as any).$test2);
});
test("registerComponent by class works correctly", async(t) => {
test("registerComponent by class works correctly", async (t) => {
const defaultComponentCount = GrimoireInterface.componentDeclarations.toArray().length;

class Aaa extends Component {
Expand Down Expand Up @@ -237,7 +237,7 @@ test("registerComponent by class works correctly", async(t) => {

t.truthy((bbb2 as any).overridedFunc() === 7);
});
test("registerComponent works correctly4", async(t) => {
test("registerComponent works correctly4", async (t) => {
const defaultComponentCount = GrimoireInterface.componentDeclarations.toArray().length;
class Aaa extends Component {
public static componentName = "Aaa";
Expand Down Expand Up @@ -346,10 +346,10 @@ test("throw error on attempt registerComponent/Node by duplicate name.", t => {
});
});

test("register and resolvePlugins works preperly", async() => {
test("register and resolvePlugins works preperly", async () => {
const spy1 = spy();
const spy2 = spy();
const wrapPromise: any = function(s) {
const wrapPromise: any = function (s) {
return () => {
return new Promise(resolve => {
s();
Expand Down Expand Up @@ -407,8 +407,8 @@ test("import works preperly", async t => {
GrimoireInterface.lib.core = {} as any;
(GrimoireInterface as any).lib.core.Core = { GomlNode: 7 };

t.truthy(GrimoireInterface.import("grimoirejs") === GrimoireInterface);
t.truthy(GrimoireInterface.import("grimoirejs/ref") === GrimoireInterface);
t.truthy(GrimoireInterface.import("grimoirejs").default === GrimoireInterface);
t.truthy(GrimoireInterface.import("grimoirejs/ref", true) === GrimoireInterface);
t.truthy(GrimoireInterface.import("grimoirejs-hoge") === GrimoireInterface.lib.hoge);
t.truthy(GrimoireInterface.import("grimoirejs-hoge/ref") === GrimoireInterface.lib.hoge);

Expand Down

0 comments on commit ab91d5e

Please sign in to comment.