Skip to content

Commit c4b2d91

Browse files
committed
init
0 parents  commit c4b2d91

9 files changed

+168
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
.DS_Store

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry=https://registry.npmjs.org/

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2022 facing-dev
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "vue-facing-decorator",
3+
"version": "0.0.1",
4+
"description": "",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "MIT",
11+
"types": "dist/index.d.ts",
12+
"peerDependencies": {
13+
"vue": "^3.0.0"
14+
}
15+
}

src/component.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { defineComponent } from 'vue';
2+
import { obtainSlot } from './utils';
3+
function makeObject(names:string[],obj:any){
4+
return names.reduce<Record<string, any>>((pv, cv) => {
5+
pv[cv] = obj[cv]
6+
return pv
7+
}, {})
8+
}
9+
export function Component(cons: { new(): any, prototype: any }) {
10+
const slot = obtainSlot(cons.prototype)
11+
const sample = new cons
12+
const proto = cons.prototype
13+
const methodNames = Object.getOwnPropertyNames(cons.prototype).filter(name => {
14+
if (name === 'constructor') {
15+
return false
16+
}
17+
if (typeof proto[name] === 'function') {
18+
return true
19+
}
20+
})
21+
22+
const dataNames = Object.getOwnPropertyNames(sample)
23+
24+
const def = defineComponent({
25+
data() {
26+
return makeObject(dataNames,sample)
27+
},
28+
methods: makeObject(methodNames,proto)
29+
})
30+
return def as any
31+
32+
33+
}

src/index.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
export { Component } from './component'
3+
import { ComponentInternalInstance, ComponentPublicInstance, Slots, nextTick, WatchOptions, WatchStopHandle } from 'vue'
4+
5+
// export declare class Base {
6+
7+
// $: ComponentInternalInstance;
8+
// $data: any//D;
9+
// $props: any//MakeDefaultsOptional extends true ? Partial<Defaults> & Omit<P & PublicProps, keyof Defaults> : P & PublicProps;
10+
// $attrs: any//Data;
11+
// $refs: any//Data;
12+
// $slots: Slots;
13+
// $root: ComponentPublicInstance | null;
14+
// $parent: ComponentPublicInstance | null;
15+
// $emit: any// EmitFn<E>;
16+
// $el: any;
17+
// $options: any//Options & MergedComponentOptionsOverride;
18+
// $forceUpdate: () => void;
19+
// $nextTick: typeof nextTick;
20+
// $watch: { (source: string | Function, cb: Function, options?: WatchOptions): WatchStopHandle };
21+
22+
// }
23+
24+
export class Base {
25+
26+
$!: ComponentInternalInstance;
27+
$data!: any//D;
28+
$props!: any//MakeDefaultsOptional extends true ? Partial<Defaults> & Omit<P & PublicProps, keyof Defaults> : P & PublicProps;
29+
$attrs!: any//Data;
30+
$refs!: any//Data;
31+
$slots!: Slots;
32+
$root!: ComponentPublicInstance | null;
33+
$parent!: ComponentPublicInstance | null;
34+
$emit!: any// EmitFn<E>;
35+
$el!: any;
36+
$options!: any//Options & MergedComponentOptionsOverride;
37+
$forceUpdate!: () => void;
38+
$nextTick!: typeof nextTick;
39+
$watch!: { (source: string | Function, cb: Function, options?: WatchOptions): WatchStopHandle };
40+
41+
}

src/utils.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const SlotSymbol = Symbol('vue-facing-decorator-slot')
2+
class Slot {
3+
4+
}
5+
6+
export function makeSlot(obj: any): Slot {
7+
if (obj[SlotSymbol]) {
8+
throw ''
9+
}
10+
return obj[SlotSymbol] = new Slot
11+
}
12+
export function getSlot(obj: any): Slot | undefined {
13+
return obj[SlotSymbol]
14+
}
15+
16+
export function obtainSlot(obj: any): Slot {
17+
const slot = getSlot(obj)
18+
if (slot) {
19+
return slot
20+
}
21+
return makeSlot(obj)
22+
23+
24+
}

tsconfig.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "./dist",
4+
"baseUrl": ".",
5+
"rootDir": "./src",
6+
"moduleResolution": "node",
7+
"module": "ESNext",
8+
"target": "ES6",
9+
"strict": true,
10+
"sourceMap": true,
11+
"lib": [
12+
"esnext"
13+
],
14+
"allowJs": true,
15+
"skipLibCheck": true,
16+
"esModuleInterop": true,
17+
"isolatedModules": true,
18+
"emitDeclarationOnly": false,
19+
"experimentalDecorators": true,
20+
"composite": false,
21+
"declaration": true,
22+
"declarationMap": true,
23+
"noUnusedLocals": false
24+
},
25+
"include": [
26+
"./src/**/*.ts",
27+
],
28+
}

0 commit comments

Comments
 (0)