Skip to content

Commit

Permalink
add context.instance
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhan committed Feb 24, 2022
1 parent 5165d5d commit 5f4951f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
10 changes: 1 addition & 9 deletions index.js
Expand Up @@ -99,15 +99,7 @@ function getComputedWatcher(name, fn) {

function getComponentContext(instance) {
return {
el() {
return instance.el;
},
owner() {
return instance.owner;
},
parentComponent() {
return instance.parentComponent;
},
instance,
dispatch(...args) {
instance.dispatch.apply(instance, args);
},
Expand Down
16 changes: 8 additions & 8 deletions test/lifeCycle.spec.js
Expand Up @@ -234,10 +234,10 @@ describe('[life cycle]: ', () => {

onConstruct(function (options) {
expect(options.from).toBe('err');
// expect(typeof context.template).toBe('string');
// expect(context.data).toBeUndefined();
// expect(context.scope).toBeUndefined();
expect(context.owner()).toBeUndefined();
expect(typeof context.instance.template).toBe('string');
expect(context.instance.data).toBeUndefined();
expect(context.instance.scope).toBeUndefined();
expect(context.instance.owner).toBeUndefined();
});
});

Expand Down Expand Up @@ -342,12 +342,12 @@ describe('[life cycle]: ', () => {
});

onCreated(function () {
expect(context.el().tagName).toBe('U');
expect(context.instance.el.tagName).toBe('U');
uState.created = 1;
});

onAttached(function () {
expect(context.el().tagName).toBe('U');
expect(context.instance.el.tagName).toBe('U');
uState.attached = 1;
});

Expand Down Expand Up @@ -377,12 +377,12 @@ describe('[life cycle]: ', () => {
})

onCreated(function () {
expect(context.el().tagName).toBe('B');
expect(context.instance.el.tagName).toBe('B');
mainState.created = 1;
})

onAttached(function () {
expect(context.el().tagName).toBe('B');
expect(context.instance.el.tagName).toBe('B');
mainState.attached = 1;
});

Expand Down
6 changes: 3 additions & 3 deletions test/messages.spec.js
Expand Up @@ -48,7 +48,7 @@ describe('[messages]: ', () => {
});

onAttached(function () {
item = context.el();
item = context.instance.el;
context.dispatch('UI:select-item-attached');
});

Expand Down Expand Up @@ -155,7 +155,7 @@ describe('[messages]: ', () => {
});

onAttached(function () {
item = context.el();
item = context.instance.el;
context.dispatch('UI:select-item-attached');
});

Expand Down Expand Up @@ -276,7 +276,7 @@ describe('[messages]: ', () => {
});

onAttached(function () {
item = context.el();
item = context.instance.el;
context.dispatch('UI:select-item-attached');
});

Expand Down
4 changes: 1 addition & 3 deletions types/index.d.ts
Expand Up @@ -3,9 +3,7 @@ interface DataObj {
[key: string]: any;
}
interface ComponentContext {
el(): Component['el'];
owner(): Component | undefined;
parentComponent(): Component['parentComponent'];
instance: Component;
dispatch: Component['dispatch'];
fire: Component['fire'];
ref: Component['ref'];
Expand Down

0 comments on commit 5f4951f

Please sign in to comment.