diff --git a/.changeset/empty-flies-teach.md b/.changeset/empty-flies-teach.md new file mode 100644 index 0000000..5b51efa --- /dev/null +++ b/.changeset/empty-flies-teach.md @@ -0,0 +1,17 @@ +--- +'@difizen/babel-preset-mana': patch +'@difizen/mana-observable': patch +'@difizen/umi-plugin-mana': patch +'@difizen/mana-syringe': patch +'@difizen/mana-common': patch +'@difizen/mana-react': patch +'@difizen/mana-react-example': patch +'@difizen/mana-core': patch +'@difizen/mana-l10n': patch +'@difizen/mana-app': patch +'@difizen/mana-umi-example': patch +'@difizen/mana-ui': patch +'@difizen/mana-docs': patch +--- + +You can now define metadata for views through view decorators, and view components can be React Lazy components, so dynamic components are also supported. diff --git a/packages/mana-core/src/view/decorator.spec.tsx b/packages/mana-core/src/view/decorator.spec.tsx new file mode 100644 index 0000000..3d338d4 --- /dev/null +++ b/packages/mana-core/src/view/decorator.spec.tsx @@ -0,0 +1,22 @@ +import 'react'; +import assert from 'assert'; +import 'reflect-metadata'; + +import { view } from './decorator'; +import { BaseView } from './default-view'; +import { ViewComponentToken, ViewDefineToken } from './view-protocol'; + +describe('app', () => { + it('#view factory', () => { + @view('foo') + class Foo extends BaseView {} + assert(Reflect.getMetadata(ViewDefineToken, Foo) === 'foo'); + }); + it('#view meta', () => { + const FooRender = () => <>; + @view({ id: 'foo', component: FooRender }) + class Foo extends BaseView {} + assert(Reflect.getMetadata(ViewDefineToken, Foo) === 'foo'); + assert(Reflect.getMetadata(ViewComponentToken, Foo) === FooRender); + }); +}); diff --git a/packages/mana-core/src/view/decorator.ts b/packages/mana-core/src/view/decorator.ts index 9685a34..2c87b93 100644 --- a/packages/mana-core/src/view/decorator.ts +++ b/packages/mana-core/src/view/decorator.ts @@ -1,5 +1,3 @@ -import { isPromise } from 'util/types'; - import type { Newable } from '@difizen/mana-common'; import type { Syringe } from '@difizen/mana-syringe'; import { registerSideOption } from '@difizen/mana-syringe';