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

Allow super_fn argument passing from mixins #206

Merged
merged 1 commit into from Mar 2, 2017
Merged

Allow super_fn argument passing from mixins #206

merged 1 commit into from Mar 2, 2017

Conversation

w33ble
Copy link
Contributor

@w33ble w33ble commented Mar 2, 2017

When a mixin calls super_fn, the arguments are currently bound to the original call, which makes it impossible to do some more advanced things, like override set for example.

function compressionPlugin() {
  return {
    set: set
  }

  function set(super_fn, key, value) {
    var newValue = 'MODIFIED' + value;
    super_fn(key, newValue)
  }
}

As a plugin author, you may expect that calling set('foo', 'bar') results in MODIFIEDbar being stored. But because the original args value, bar, is bound, that's the value that gets stored.

With this PR, any arguments passed into super_fn override the original values, so calling set('foo', 'bar') with this PR results in MODIFIEDbar being stored.

Additionally, any additional arguments passed in the original call will continue to be passed through unmodified.

I'm not entirely sure how to write tests for this change, short of writing a plugin that would use this change. That said, I would like to modify #204 to use it...

@marcuswestin
Copy link
Owner

Looks good! This will break in legacy IE so I'll have to make some changes but I think the approach is good! Stay tuned for final code...

@marcuswestin marcuswestin merged commit 8bd09ca into marcuswestin:master Mar 2, 2017
marcuswestin added a commit that referenced this pull request Mar 2, 2017
…erlying plugin are not overriden by an intermediate plugin. Also remove super_fn.args property, since plugins can now give arguments to super_fn directly. See #206 for more info.
@marcuswestin
Copy link
Owner

Done! Can you please double check https://github.com/marcuswestin/store.js/blob/master/tests/tests.js#L61 to ensure that it behaves in the way you'd expect it to?

@w33ble
Copy link
Contributor Author

w33ble commented Mar 2, 2017

I think that looks right. I don't see a test that is checking the arguments to the super_fn, but the use in the second addPlugin there is how I would expect to use it. Sorry, now I see how that test works. Yup, that looks right.

I'll update #204 and report back.

@marcuswestin
Copy link
Owner

👍

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.

None yet

2 participants