Skip to content

Commit

Permalink
feat(omi): provide and inject supported
Browse files Browse the repository at this point in the history
  • Loading branch information
dntzhang committed Aug 5, 2021
1 parent 76892e0 commit dba1177
Show file tree
Hide file tree
Showing 14 changed files with 240 additions and 27 deletions.
10 changes: 8 additions & 2 deletions packages/omi/dist/omi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ declare namespace Omi {
normalizedNodeName?: string;
elementId: number;
isInstalled: boolean;
provide?: { [key: string]: any };
inject?: string[];
injection?: { [key: string]: any };

update?(ignoreAttrs?: boolean, updateSelf?: boolean): void;
forceUpdate?(): void;
Expand Down Expand Up @@ -140,6 +143,9 @@ declare namespace Omi {
normalizedNodeName?: string;
elementId: number;
isInstalled: boolean;
provide?: { [key: string]: any };
inject?: string[];
injection?: { [key: string]: any };

update?(ignoreAttrs?: boolean, updateSelf?: boolean): void;
forceUpdate?(): void;
Expand Down Expand Up @@ -168,8 +174,8 @@ declare namespace Omi {
}

var createElement: typeof h;
function cloneElement<P>(vnode: VNode<Partial<P>>, props: Partial<P>, ...children: ComponentChildren[]): VNode<Partial<P>>;

function cloneElement<P>(vnode: VNode<Partial<P>>, props: Partial<P>, ...children: ComponentChildren[]): VNode<Partial<P>>;

function render(vnode: ComponentChild, parent: string | Element | Document | ShadowRoot | DocumentFragment, store?: object): any;

Expand Down
31 changes: 25 additions & 6 deletions packages/omi/dist/omi.dev.js

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

2 changes: 1 addition & 1 deletion packages/omi/dist/omi.dev.js.map

Large diffs are not rendered by default.

31 changes: 25 additions & 6 deletions packages/omi/dist/omi.esm.js

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

2 changes: 1 addition & 1 deletion packages/omi/dist/omi.esm.js.map

Large diffs are not rendered by default.

21 changes: 17 additions & 4 deletions packages/omi/dist/omi.js

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

2 changes: 1 addition & 1 deletion packages/omi/dist/omi.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/omi/dist/omi.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/omi/dist/omi.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/omi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "omi",
"version": "6.20.1",
"version": "6.21.0",
"description": "Front End Cross-Frameworks Framework.",
"main": "dist/omi.js",
"jsnext:main": "dist/omi.esm.js",
Expand Down
10 changes: 8 additions & 2 deletions packages/omi/src/omi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ declare namespace Omi {
normalizedNodeName?: string;
elementId: number;
isInstalled: boolean;
provide?: { [key: string]: any };
inject?: string[];
injection?: { [key: string]: any };

update?(ignoreAttrs?: boolean, updateSelf?: boolean): void;
forceUpdate?(): void;
Expand Down Expand Up @@ -140,6 +143,9 @@ declare namespace Omi {
normalizedNodeName?: string;
elementId: number;
isInstalled: boolean;
provide?: { [key: string]: any };
inject?: string[];
injection?: { [key: string]: any };

update?(ignoreAttrs?: boolean, updateSelf?: boolean): void;
forceUpdate?(): void;
Expand Down Expand Up @@ -168,8 +174,8 @@ declare namespace Omi {
}

var createElement: typeof h;
function cloneElement<P>(vnode: VNode<Partial<P>>, props: Partial<P>, ...children: ComponentChildren[]): VNode<Partial<P>>;

function cloneElement<P>(vnode: VNode<Partial<P>>, props: Partial<P>, ...children: ComponentChildren[]): VNode<Partial<P>>;

function render(vnode: ComponentChild, parent: string | Element | Document | ShadowRoot | DocumentFragment, store?: object): any;

Expand Down
2 changes: 1 addition & 1 deletion packages/omi/src/omi.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const omi = {

options.root.Omi = omi
options.root.omi = omi
options.root.Omi.version = '6.20.1'
options.root.Omi.version = '6.21.0'

export default omi

Expand Down
17 changes: 17 additions & 0 deletions packages/omi/src/we-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ export default class WeElement extends HTMLElement {
p = p.parentNode || p.host
}

if (this.inject) {
this.injection = {}
p = this.parentNode
let provide
while (p && !provide) {
provide = p.provide
p = p.parentNode || p.host
}
if (provide) {
this.inject.forEach(injectKey => {
this.injection[injectKey] = provide[injectKey]
})
} else {
throw 'The provide prop was not found on the parent node or the provide type is incorrect.'
}
}

this.attrsToProps()

this.beforeInstall()
Expand Down

0 comments on commit dba1177

Please sign in to comment.