Skip to content
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

Merged
merged 2 commits into from
Aug 20, 2016
Merged

Conversation

priezz
Copy link
Contributor

@priezz priezz commented Aug 17, 2016

This PR contains a small change to fix passing the wrong context into before and after method hooks. With this fix hooks get the same context as the original method, so the goodies like this.userId become available for them as well.

As the changes proposed are really small, there are no additional tests/docs.

Fix passing the wrong context into before and after method hooks
@jshimko
Copy link
Contributor

jshimko commented Aug 17, 2016

Thanks for the PR!

I think we might want to consider changing those callbacks to arrow functions so the self isn't necessary. That's what we tend to do everywhere else. It'd be nice to be consistent.

Thoughts @aaronjudd @mikemurray?

@jshimko
Copy link
Contributor

jshimko commented Aug 17, 2016

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
      });

...

@priezz
Copy link
Contributor Author

priezz commented Aug 17, 2016

Sure, arrow functions will do the thing as well

@aaronjudd aaronjudd added this to the v0.16.0 milestone Aug 18, 2016
@aaronjudd aaronjudd added review and removed ready labels Aug 19, 2016
@aaronjudd
Copy link
Contributor

aaronjudd commented Aug 19, 2016

👍 accepting, @jshimko we can always update/cleanup (now if you want), or when we review hooks overall.

Approved with PullApprove

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.

@priezz
Copy link
Contributor Author

priezz commented Aug 20, 2016

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?

@aaronjudd
Copy link
Contributor

@priezz thanks, looks good.

@jshimko
Copy link
Contributor

jshimko commented Aug 20, 2016

👍

Approved with PullApprove

@jshimko jshimko merged commit fc17fb7 into reactioncommerce:development Aug 20, 2016
@jshimko jshimko removed the review label Aug 20, 2016
jshimko added a commit that referenced this pull request Aug 23, 2016
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants