-
Couldn't load subscription status.
- Fork 1.7k
Pass block info to extension methods #2102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -391,23 +391,22 @@ class ExtensionManager { | |
| } | ||
| break; | ||
| default: | ||
| if (!blockInfo.opcode) { | ||
| throw new Error('Missing opcode for block'); | ||
| } | ||
|
|
||
| blockInfo.func = blockInfo.func ? this._sanitizeID(blockInfo.func) : blockInfo.opcode; | ||
| if (blockInfo.opcode) { | ||
| const funcName = blockInfo.func ? this._sanitizeID(blockInfo.func) : blockInfo.opcode; | ||
|
|
||
| // Avoid promise overhead if possible | ||
| if (dispatch._isRemoteService(serviceName)) { | ||
| blockInfo.func = dispatch.call.bind(dispatch, serviceName, blockInfo.func); | ||
| } else { | ||
| const serviceObject = dispatch.services[serviceName]; | ||
| const func = serviceObject[blockInfo.func]; | ||
| if (func) { | ||
| blockInfo.func = func.bind(serviceObject); | ||
| // Avoid promise latency unless necessary | ||
| if (dispatch._isRemoteService(serviceName)) { | ||
| blockInfo.func = (args, util) => dispatch.call(serviceName, funcName, args, util, blockInfo); | ||
| } else { | ||
| throw new Error(`Could not find extension block function called ${blockInfo.func}`); | ||
| const serviceObject = dispatch.services[serviceName]; | ||
| if (!serviceObject[funcName]) { | ||
| // The function might show up later as a dynamic property of the service object | ||
| log.warn(`Could not find extension block function called ${funcName}`); | ||
|
||
| } | ||
| blockInfo.func = (args, util) => serviceObject[funcName](args, util, blockInfo); | ||
| } | ||
| } else { | ||
| throw new Error('Missing opcode for block'); | ||
| } | ||
| break; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for rearranging this conditional (from the previous structure of falsey check and early exit)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's kind of silly... but this isn't legal JavaScript:
default: if (!blockInfo.opcode) { throw new Error('Missing opcode for block'); } const funcName = "stuff"; // it's not legal to make a new `const` hereYou can do it if you introduce a new scope with
{}which sort of naturally led me to the arrangement proposed here...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmmm okay. I think I'd prefer adding the new block of scope only because it's easier to read an early exit vs. keeping track of which block of code corresponds to which part of the if/else etc. Esp. since there are nested ifs involved here.