Skip to content

Commit

Permalink
fix(wire-service): add lifecycle hook guards (#1092)
Browse files Browse the repository at this point in the history
* fix(wire-service): add lifecycle hook guards

* wip: fix assert and error message
  • Loading branch information
Trevor authored Mar 5, 2019
1 parent c2c1097 commit dfa87d1
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/@lwc/wire-service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ const wireService = {

connected: (cmp: LightningElement, data: object, def: ElementDef, context: Context) => {
let listeners: NoArgumentListener[];
if (process.env.NODE_ENV !== 'production') {
assert.isTrue(!def.wire || context[CONTEXT_ID], 'wire service was not initialized prior to component creation: "connected" service hook invoked without necessary context');
}
if (!def.wire || !(listeners = context[CONTEXT_ID][CONTEXT_CONNECTED])) {
return;
}
Expand All @@ -128,6 +131,9 @@ const wireService = {

disconnected: (cmp: LightningElement, data: object, def: ElementDef, context: Context) => {
let listeners: NoArgumentListener[];
if (process.env.NODE_ENV !== 'production') {
assert.isTrue(!def.wire || context[CONTEXT_ID], 'wire service was not initialized prior to component creation: "disconnected" service hook invoked without necessary context');
}
if (!def.wire || !(listeners = context[CONTEXT_ID][CONTEXT_DISCONNECTED])) {
return;
}
Expand Down

0 comments on commit dfa87d1

Please sign in to comment.