From 253a4decebfacfe959e1c073ffb04c860b80eabc Mon Sep 17 00:00:00 2001 From: ienaga Date: Tue, 4 Jul 2023 21:43:52 +0900 Subject: [PATCH 1/2] =?UTF-8?q?#88=20TypeScript=E3=81=A7=E3=81=AE=E9=96=8B?= =?UTF-8?q?=E7=99=BA=E7=92=B0=E5=A2=83=E3=81=AE=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/application/Application.ts | 61 ++++++++++++----------------- src/application/Context.ts | 1 - src/application/variable/Context.ts | 3 +- src/index.ts | 2 + src/interface/ConfigImpl.ts | 6 ++- 6 files changed, 33 insertions(+), 42 deletions(-) diff --git a/package.json b/package.json index 0112baa..fcb4eb1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@next2d/framework", "description": "It is a framework dedicated to Next2D that enables scene management by URL (SPA), which has been difficult with conventional Canvas/WebGL applications, and simplifies readability and shareability by fixing the development pattern (MVVM).", - "version": "1.5.11", + "version": "1.5.12", "homepage": "https://next2d.app", "bugs": "https://github.com/Next2D/Framework/issues/new", "author": "Toshiyuki Ienaga (https://github.com/ienaga/)", diff --git a/src/application/Application.ts b/src/application/Application.ts index 8714722..4359560 100644 --- a/src/application/Application.ts +++ b/src/application/Application.ts @@ -34,7 +34,6 @@ export class Application private readonly _$removeResponse: RemoveResponse; private _$popstate: boolean; private _$currentName: string; - private readonly _$promises: Promise[]; /** * @constructor @@ -45,8 +44,6 @@ export class Application $setConfig(config); $setPackages(packages); - this._$promises = [$createContext(config)]; - /** * @type {QueryParser} * @private @@ -108,21 +105,20 @@ export class Application * @private */ this._$currentName = "top"; - - // initial processing - this.initialize(); } /** - * @description constructorが起動した後にコールされます。(初回起動時のみコールされます。) - * Called after the constructor is invoked. (Called only the first time it is invoked.) + * @description Next2Dのアプリを起動します + * Launch the Next2D application * - * @return {void} + * @return {Application} * @method - * @abstract + * @public */ - // eslint-disable-next-line no-empty-function - initialize (): void {} + run () + { + return $createContext(config); + } /** * @description 指定のViewを起動して、描画を開始します。引数を指定しない場合はURLをパースしてViewを起動します。 @@ -136,32 +132,23 @@ export class Application */ gotoView (name: string = ""): Promise { - return Promise - .all(this._$promises) - .then((): Promise[]> => - { - // reset - if (this._$promises.length) { - this._$promises.length = 0; - } - - const promises: Promise[] = []; - if (config.loading) { - /** - * ローディング表示を起動 - * Launch loading display - */ - this._$loading.start(); - - /** - * 現時点の描画をBitmapにして処理の負担を減らす - * Reduce the processing burden by making the current drawing a Bitmap. - */ - promises.push(this._$capture.execute()); - } + const promises: Promise[] = []; + if (config.loading) { + /** + * ローディング表示を起動 + * Launch loading display + */ + this._$loading.start(); + + /** + * 現時点の描画をBitmapにして処理の負担を減らす + * Reduce the processing burden by making the current drawing a Bitmap. + */ + promises.push(this._$capture.execute()); + } - return Promise.all(promises); - }) + return Promise + .all(promises) .then((): Promise => { /** diff --git a/src/application/Context.ts b/src/application/Context.ts index 3cda02b..7e7722e 100644 --- a/src/application/Context.ts +++ b/src/application/Context.ts @@ -1,5 +1,4 @@ import { ToCamelCase } from "../domain/convert/ToCamelCase"; -import { Event } from "@next2d/events"; import { packages } from "./variable/Packages"; import type { View } from "../view/View"; import type { ViewModel } from "../view/ViewModel"; diff --git a/src/application/variable/Context.ts b/src/application/variable/Context.ts index 14606da..3023559 100644 --- a/src/application/variable/Context.ts +++ b/src/application/variable/Context.ts @@ -16,8 +16,7 @@ export let context: Context; */ export const $createContext = (config: ConfigImpl): Promise => { - return window - .next2d + return next2d .createRootMovieClip( config.stage.width, config.stage.height, diff --git a/src/index.ts b/src/index.ts index 48ebe41..e1bc683 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,7 @@ import { MovieClipContent } from "./application/content/MovieClipContent"; import { ShapeContent } from "./application/content/ShapeContent"; import { TextFieldContent } from "./application/content/TextFieldContent"; import { VideoContent } from "./application/content/VideoContent"; +import { ConfigImpl } from "./interface/ConfigImpl"; import { packages } from "./application/variable/Packages"; import { context } from "./application/variable/Context"; import { cache } from "./application/variable/Cache"; @@ -29,6 +30,7 @@ export { ShapeContent, TextFieldContent, VideoContent, + ConfigImpl, packages, context, cache, diff --git a/src/interface/ConfigImpl.ts b/src/interface/ConfigImpl.ts index 2e55daa..e877e9b 100644 --- a/src/interface/ConfigImpl.ts +++ b/src/interface/ConfigImpl.ts @@ -3,7 +3,11 @@ import { RoutingImpl } from "./RoutingImpl"; import { LoadingImpl } from "./LoadingImpl"; import { GotoViewImpl } from "./GotoViewImpl"; -export interface ConfigImpl { +interface BaseConfigImpl { + [key: string]: any +} + +export interface ConfigImpl extends BaseConfigImpl { platform: string; stage: StageImpl; routing?: { From 3fab39cf7a502236536d4759b25f34b986f738e8 Mon Sep 17 00:00:00 2001 From: ienaga Date: Tue, 4 Jul 2023 21:54:47 +0900 Subject: [PATCH 2/2] =?UTF-8?q?#88=20TypeScript=E3=81=A7=E3=81=AE=E9=96=8B?= =?UTF-8?q?=E7=99=BA=E7=92=B0=E5=A2=83=E3=81=AE=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/application/ApplicationTest.ts | 9 +++++++-- src/application/Application.ts | 4 ++-- src/application/variable/Context.ts | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/__tests__/application/ApplicationTest.ts b/__tests__/application/ApplicationTest.ts index d0c5bd4..be44f72 100644 --- a/__tests__/application/ApplicationTest.ts +++ b/__tests__/application/ApplicationTest.ts @@ -10,7 +10,7 @@ import { $createContext } from "../../src/application/variable/Context"; describe("ApplicationTest", () => { - test("initialize test", () => { + test("run test", () => { const config = { "platform": "web", @@ -34,7 +34,12 @@ describe("ApplicationTest", () => const app = new Application(config, packages); - expect(app.initialize()).toBe(undefined); + app + .run() + .then(() => + { + expect(app instanceof Application).toBe(true); + }); }); test("loading test", () => diff --git a/src/application/Application.ts b/src/application/Application.ts index 4359560..71f7b5b 100644 --- a/src/application/Application.ts +++ b/src/application/Application.ts @@ -111,11 +111,11 @@ export class Application * @description Next2Dのアプリを起動します * Launch the Next2D application * - * @return {Application} + * @return {Promise} * @method * @public */ - run () + run (): Promise { return $createContext(config); } diff --git a/src/application/variable/Context.ts b/src/application/variable/Context.ts index 3023559..14606da 100644 --- a/src/application/variable/Context.ts +++ b/src/application/variable/Context.ts @@ -16,7 +16,8 @@ export let context: Context; */ export const $createContext = (config: ConfigImpl): Promise => { - return next2d + return window + .next2d .createRootMovieClip( config.stage.width, config.stage.height,