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

Create a backwards compat shim for backbone views/human views. #33

Closed
latentflip opened this issue Jul 25, 2014 · 6 comments
Closed

Create a backwards compat shim for backbone views/human views. #33

latentflip opened this issue Jul 25, 2014 · 6 comments

Comments

@latentflip
Copy link
Contributor

Suggested by: @whobubble, the two things that are tripping him up transitioning from humanview are a lack of this.$ and this.$el, we've covered this.$ already in the learn page, but a mixin that also updated this.$el would be really useful too.

I think it would be as little code as this: but it's late and it's been a long day :)

derived: {
   '$el': {
     deps: ['el'],
     fn: function () {
       if (this.el) return this.$(this.el);
     }
}
@kamilogorek
Copy link
Contributor

Agree. I guess we could also add some kind of error/info if there's no this.el to not confuse users.

@whobubble
Copy link

Created a mixin using the pattern outlined above: https://github.com/whobubble/ampersand-view-jquery-mixin. Not sure about the hard dependency to jQuery, which puts the 2M down although jQuery might already be required somewhere else. I guess it is better to be explicit regarding this dep and incur the risk of jQuery being present in node_modules tree more than once.

@prust
Copy link

prust commented Jul 30, 2014

@whobubble: Thanks for writing this! Our team will use it when we start transitioning apps to ampersand.

incur the risk of jQuery being present in node_modules tree more than once

I was recently surprised to discover that npm won't install a dependency more than once if a matching version is already present in a parent (or grandparent) node_modules folder. This is ok b/c when require() loads from node_modules, it starts in node_modules of the current directory, then tries node_modules in the parent folder, the grandparent folder, and so on until it reaches the root.

So if your jQuery semver string is inclusive enough and matches what's already installed at a higher level, npm won't install jQuery twice. Since the view-jquery mixin itself doesn't need a specific version of jQuery, perhaps "jquery": "*" would be better than what npm --save generates ("jquery": "^2.1.1")?

@whobubble
Copy link

@prust: I tested it and it works as you describe it: using "jquery": "*" in the mixin makes npm hold off on downloading jQuery again when any version of it is already present in a parent directory in node_modules. I changed the package.json file and bumped the version. Thanks!

@prust
Copy link

prust commented Jul 30, 2014

@whobubble: you're welcome; I'm glad it worked! 😄

@latentflip
Copy link
Contributor Author

Going to close this as it's covered pretty well by @whobubble here: https://github.com/whobubble/ampersand-view-jquery-mixin Awesome work all!

kamilogorek pushed a commit that referenced this issue Jul 21, 2017
Update deps to survive get-object-path@^0.0.2 being removed from npm
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

No branches or pull requests

4 participants