-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Fix wrong method hooks context #1307
Conversation
Fix passing the wrong context into before and after method hooks
Thanks for the PR! I think we might want to consider changing those callbacks to arrow functions so the Thoughts @aaronjudd @mikemurray? |
To clarify... MethodHooks._wrappers[methodName] = function () {
// Get arguments you can mutate
let args = _.toArray(arguments);
let beforeResult;
// Call the before hooks
let beforeHooks = MethodHooks._beforeHooks[methodName];
_.each(beforeHooks, (beforeHook, hooksProcessed) => {
beforeResult = beforeHook.call(this, {
result: undefined,
error: undefined,
arguments: args,
hooksProcessed: hooksProcessed
});
... |
Sure, arrow functions will do the thing as well |
👍 accepting, @jshimko we can always update/cleanup (now if you want), or when we review hooks overall. it's true that we don't promote the use of "self" anymore, always preferring es6 structures.. just for cleanliness, this is still a fix. |
Just changed to the arrow function use... Are there any other steps required from my side regarding this PR or I just wait for the merge? |
@priezz thanks, looks good. |
* development: (27 commits) Release 0.15.1 (#1314) Fix wrong method hooks context (#1307) - function isSoldOut() should return true if quantity is <= 0, not only if it is === 0. (#1311) Remove jquery-ui (#1310) Taxes (#1289) Fix Stripe refunds and Double Discounts (#1304) fix refunds and discounts for authorize.net (#1279) Fix Braintree discounts and refunds (#1265) Allow any user who has the createProduct permission to also delete products (#1263) Remove bash script from postinstall to fix Windows installs (#1299) update cardNumber schemas Fix PayPal PayFlow discounts and refunds (#1275) logout and hasPermission updates (#1290) Create email job queue and Reaction.Email namespace (#1282) updated package.json (#1286) Update circle node (#1281) Use forked version of authorize.net that doesn't have vulnerability (#1252) fix for #1072 (#1247) Temporarily bypass failiing inventory test (#1280) Fix inventory tests (#1254) ... # Conflicts: # .codeclimate.yml # .eslintignore # .meteor/versions # client/modules/core/main.js # imports/plugins/core/orders/client/templates/workflow/shippingTracking.js # imports/plugins/core/taxes/client/settings/custom.js # imports/plugins/core/taxes/client/settings/settings.js # imports/plugins/core/taxes/server/methods/methods.js # imports/plugins/included/authnet/server/methods/authnet.js # imports/plugins/included/braintree/server/methods/braintreeApi.js # imports/plugins/included/braintree/server/methods/braintreeMethods.js # imports/plugins/included/braintree/server/methods/braintreeapi-methods-refund.app-test.js # imports/plugins/included/example-paymentmethod/server/methods/example-payment-methods.app-test.js # imports/plugins/included/inventory/server/hooks/hooks.js # imports/plugins/included/inventory/server/hooks/inventory-hooks.app-test.js # imports/plugins/included/inventory/server/methods/inventory.js # imports/plugins/included/inventory/server/methods/statusChanges.js # imports/plugins/included/launchdock-connect/client/templates/dashboard.js # imports/plugins/included/paypal/server/methods/payflowpro-methods-refund.app-test.js # imports/plugins/included/paypal/server/methods/payflowproApi.js # imports/plugins/included/paypal/server/methods/payflowproMethods.js # imports/plugins/included/product-variant/client/templates/products/productDetail/variants/variantForm/variantForm.js # imports/plugins/included/taxes-avalara/server/hooks/hooks.js # imports/plugins/included/taxes-taxcloud/server/hooks/hooks.js # imports/plugins/included/taxes-taxjar/server/hooks/hooks.js # lib/collections/helpers.js # package.json # server/api/core/import.js # server/methods/catalog.js # server/methods/core/cart-remove.app-test.js # server/methods/core/orders.js # server/methods/core/shop.js
This PR contains a small change to fix passing the wrong context into
before
andafter
method hooks. With this fix hooks get the same context as the original method, so the goodies likethis.userId
become available for them as well.As the changes proposed are really small, there are no additional tests/docs.