-
-
Notifications
You must be signed in to change notification settings - Fork 364
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
Plugin Support - BETA #325
Conversation
lib/Scan.js
Outdated
debug('scan request', scanOneReq); | ||
Model.$__.base.ddb().scan(scanOneReq, function(err, data) { | ||
Model._emit('model:scan', 'request:post', {event: {scan: this, callback: next, data: data, error: err}, actions: {updateError: function(error) {err = error;}, updateData: function(myData) {data = myData}}}); |
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.
Concerned about async issues with some of these action functions
# Conflicts: # docs/_docs/model.md
…gh correctly in the event object to listeners
For the request that @mogwai had regarding async support and exiting early. Please see this branch. Things still to do on that branch:
|
@mogwai You want to pull down the branch I mentioned in #325 (comment) and see if you can create the plugin you were looking at and give me some more feedback? |
Yeah @fishcharlie I'll give it a go this week |
Hi Charlie, I'm looking into your plugins-async branch. I can see that a caching plugin could now be created using the deferredMain promise and preventing the continued execution by returning false to continue. My concern is that there is a possibility of Q.defer being removed soon? If so it might affect the way the plugin will work? |
@mogwai PR #456 should not be a breaking change. If you return or use a promise in your plugin, the code I wrote should just If you want to use Hopefully this answers your question. Let me know if it doesn't tho. I really look forward to seeing what you come up with!!! |
Well thats another thing on its own. I don't think the library should force the user to use a promise. It should check whether the return value is a promise and await it if so. Other plugins may not need to return a promise and will be forced to return I suggest changing the Plugin.js to: let result = listener.emit(type, stage, obj);
result = result.then ? await result : result; In the |
@mogwai If a plug-in returns a non promise that should be perfectly fine. I’m pretty sure await will handle that gracefully without any additional logic on our end. I could be TOTALLY wrong tho. |
Your right :) ignore that comment |
I have updated the documentation in my pluginsupport-async branch. I will be merging that branch into this PR soon (might wait for @mogwai's input first tho). I'm aiming to get this PR merged in before the next version (#464). Keep in mind this will just be a beta version and not considered stable for that release. The goal will be to gain more input and feedback from developers to solidify it in a future release. |
Pull Request Test Coverage Report for Build 735
💛 - Coveralls |
Pull Request Test Coverage Report for Build 715
💛 - Coveralls |
I have just merged the async branch into this PR. |
Plugin Support - BETA
WARNING: PLUGINS IS CURRENTLY IN BETA. THIS FUNCTIONALITY MIGHT CHANGE AT ANYTIME WITHOUT WARNING. DO NOT CONSIDER THIS FEATURE TO BE STABLE.
Summary
It's finally here (or coming soon, if this isn't merged in yet). Plugin Support is coming to Dynamoose. We are currently aiming to release this with Dynamoose version 1.2.0.
I'm creating this PR way too early. The reason for this is I'm trying to build this feature in the open to receive feedback and suggestions so the community can help build this and make it the best it can be.
Ideas/Structure
*
is passed into action, in the.on
method it will match all emitted types. Or maybe we can make bothaction
/type
andstage
optional.Ideas we are exploring
Items marked with
***
means that we are currently unsure how to implement this feature. Although it would be a cool feature, the details of the idea haven't been thought through to a level that makes implementation possible.Potential Examples
Possible Plugin Implementation
The
obj.on
method will add listeners that will be called when Dynamoose emits certain actions. It will accept 3 properties (action, [stage ,] func).action
is a higher level stage that Dynamoose will emit.stage
is a lower level stage that gives detail about where in the process Dynamoose is (for example right before AWS request, right after AWS request) all within a higher level action such as (.get, .scan, etc). Ifstage
is not passed in, the function will be called for all emitted actions that match.Adding Plugin to Model
Potential actions/types to emit
put
)**
indicates an action that has been fully implemented.Potential stages to emit
Stages (examples, depends on method):
Use Cases we need to support
Todo Items
Questions
Other Notes