Skip to content

Commit

Permalink
Merge pull request #1 from wu-component/featue/test
Browse files Browse the repository at this point in the history
fix:fix inject params bug
  • Loading branch information
canyuegongzi authored May 23, 2022
2 parents 6381c2c + 60ff6af commit 52f22d1
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/web-core-cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion packages/web-core-plus/src/decorators/InjectDecorators.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import 'reflect-metadata';
import { COMPONENT_CUSTOM_INJECT } from '../app-data';
export interface InjectOptions {
[key: string]: any;
}

export interface InjectConfig {
key?: string; // 需要接受的字段集合
attr?: string; // 需要接受的字段集合
[key: string]: any;
}

export function Inject(key: string, options: InjectOptions = {}): PropertyDecorator {
return function(target: any, attr: any) {
const keys: InjectOptions[] = Reflect.getMetadata(COMPONENT_CUSTOM_INJECT, target) ?? [];
const keys: InjectConfig[] = Reflect.getMetadata(COMPONENT_CUSTOM_INJECT, target) ?? [];
keys.push({ ...options, attr, key });
Reflect.defineMetadata(COMPONENT_CUSTOM_INJECT, keys, target);
};
Expand Down
4 changes: 4 additions & 0 deletions packages/web-plus-ui/index1.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<div style="display: flex;flex-direction: column">
<wu-plus-provide>
<wu-plus-inject></wu-plus-inject>
<wu-plus-inject-child1>
<wu-plus-inject-child2>
</wu-plus-inject-child2>
</wu-plus-inject-child1>
</wu-plus-provide>

</div>
Expand Down
13 changes: 10 additions & 3 deletions packages/web-plus-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"format": "prettier --write \"{src,apps,libs,test}/**/*.{tsx,ts}\"",
"lint": "eslint \"{src,apps,libs,test}/**/*.{tsx,ts}\" --fix",
"test": "jest -c packages/web-ui/jest.config.js",
"test:karma": "node ./node_modules/karma/bin/karma start _test_/karma.conf.js --single-run",
"build:rollup": "cross-env NODE_ENV=production rollup -c ./rollup.config.js",
"build:rollup:package": "cross-env NODE_ENV=production rollup -c ./build/build.js",
"build:rollup:package:dev": "cross-env NODE_ENV=production rollup -c ./build/build-dev.js",
Expand Down Expand Up @@ -54,6 +55,7 @@
"@types/yaml": "^1.9.7",
"@typescript-eslint/eslint-plugin": "^5.25.0",
"@typescript-eslint/parser": "^5.25.0",
"@vitejs/plugin-vue": "^2.3.1",
"autoprefixer": "^10.4.4",
"body-parser": "^1.19.0",
"cross-env": "^7.0.3",
Expand All @@ -62,7 +64,13 @@
"eslint-plugin-import": "^2.20.1",
"express": "^4.17.1",
"fs-extra": "^10.0.1",
"jasmine-core": "^4.1.1",
"jest": "^23.6.0",
"karma": "^6.3.20",
"karma-chrome-launcher": "^3.1.1",
"karma-coverage": "^2.2.0",
"karma-jasmine": "^5.0.1",
"karma-spec-reporter": "0.0.34",
"lerna": "^4.0.0",
"lodash": "^4.17.21",
"nodemon": "^1.18.9",
Expand All @@ -88,10 +96,9 @@
"tsconfig-paths": "^3.7.0",
"tslib": "^2.3.1",
"typescript": "4.5.4",
"@vitejs/plugin-vue": "^2.3.1",
"vite": "^2.9.2",
"vue-tsc": "^0.29.8",
"vue": "^3.2.25"
"vue": "^3.2.25",
"vue-tsc": "^0.29.8"
},
"dependencies": {
"@canyuegongzi/web-core-plus": "0.0.30",
Expand Down
6 changes: 4 additions & 2 deletions packages/web-plus-ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export * from './packages/wu-rate';
export * from './packages/wu-message';

/************************测试数据注入***************************/
export * from './packages/wu-inject';
export * from './packages/wu-provide';
export * from './test/wu-inject';
export * from './test/wu-inject-child1';
export * from './test/wu-inject-child2';
export * from './test/wu-provide';
export * from './packages/wu-example';
22 changes: 22 additions & 0 deletions packages/web-plus-ui/src/test/wu-inject-child1/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { h, Component, Inject, OnConnected } from '@canyuegongzi/web-core-plus';

@Component({
name: 'wu-plus-inject-child1',
})
export class WuInjectChild1 extends HTMLElement implements OnConnected {
@Inject('parentDescTitle')
public injectionName;

public connected(shadowRoot: ShadowRoot) {
console.log(this.injectionName);
}

public render(_renderProps = {}, _store = {}) {
return (
<div style={{ width: '400px', height: '48px', textAlign: 'center' }}>
一级子组件数据注入{this.injectionName?.parentDescTitle}
<slot />
</div>
);
}
}
22 changes: 22 additions & 0 deletions packages/web-plus-ui/src/test/wu-inject-child2/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { h, Component, Inject, OnConnected } from '@canyuegongzi/web-core-plus';

@Component({
name: 'wu-plus-inject-child2',
})
export class WuInjectChild2 extends HTMLElement implements OnConnected {
@Inject('parentDescTitle')
public injectionName;

public connected(shadowRoot: ShadowRoot) {
console.log(this.injectionName);
}

public render(_renderProps = {}, _store = {}) {
return (
<div style={{ width: '400px', height: '48px', textAlign: 'center' }}>
二级子组件数据注入{this.injectionName?.parentDescTitle}
<slot />
</div>
);
}
}
17 changes: 17 additions & 0 deletions packages/web-plus-ui/src/test/wu-inject/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { h, Component, Inject, OnConnected } from '@canyuegongzi/web-core-plus';

@Component({
name: 'wu-plus-inject',
})
export class WuInject extends HTMLElement implements OnConnected {
@Inject('parentDescTitle')
public injectionName;

public connected(shadowRoot: ShadowRoot) {
console.log(this.injectionName);
}

public render(_renderProps = {}, _store = {}) {
return <div style={{ width: '100vw', height: '48px', textAlign: 'center' }}>数据注入{this.injectionName?.parentDescTitle}</div>;
}
}
30 changes: 30 additions & 0 deletions packages/web-plus-ui/src/test/wu-provide/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Component, h, Method, OnConnected, Provide } from '@canyuegongzi/web-core-plus';

@Component({
name: 'wu-plus-provide',
})
export class WuProvide extends HTMLElement implements OnConnected {
public provide = '这是来自父级注入的数据';

@Provide('parentDescTitle')
public provideParentDescTitle() {
return {
parentDescTitle: this.provide,
};
}

/**
* 获取
* @private
*/
@Method()
public getProvide() {
return this.provide;
}

public render(_renderProps = {}, _store = {}) {
return <slot />;
}

public connected(shadowRoot: ShadowRoot): any {}
}
1 change: 1 addition & 0 deletions packages/web-plus-ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"include": [
"typings/*.ts",
"src/packages/**/*.tsx",
"src/test/**/*.tsx",
"./css.d.ts", //配置的.d.ts文件
"src/declarations/*.ts"
]
Expand Down

0 comments on commit 52f22d1

Please sign in to comment.