Added possibility for multiple plugin results #247
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Platforms affected
Motivation and Context
It is currently not possible to send more than one plugin response per service action call. This is not ideal in situations where a native process might generate more than one result over time.
Additionally, the API is more in line with that of cordova-android and from what I can gather also cordova-ios
Description
Related to Allow for multiple plugin results #248
The version in this branch creates a callbackId in exec.js and passes it on to preload.
preload registers this callbackId with ipcRenderer and invokes the callback.
main creates a CallbackContext with this callbackId and passes it on to the service action dispatch
service actions now have a similar API as android: (action: string, args: any, callbackContext: Object)
callbackContext provides functions
success
anderror
.Additionally, it exposes the
PluginResult
class along withsendPluginResult
. This makes it possible to send multiple results whenkeepCallback
is set totrue
.There might be a better way to provide this API to plugins.
Testing
I used document.addEventListener in the plugin sample to call a demo implementation of the new api
Checklist
(platform)
if this change only applies to one platform (e.g.(android)
)Additional notes
The API changes would break existing plugins but it would be possible to load the plugin package.json and check for an API flag. The old API would be considered deprecated until at least 5.0API flag implemented in 198cf24