BorisMoore / jsviews

Interactive data-driven views, MVVM and MVP, built on top of JsRender templates
http://www.jsviews.com/#jsviews
MIT License
855 stars 130 forks source link

Global jquery vs local jquery #343

Closed ViktorHofer closed 8 years ago

ViktorHofer commented 8 years ago

Hey Boris,

I noticed that when jQuery is globally available but I wanna use my local jQuery instance with jsviews like this:

import $ from 'jquery';
require('jsviews')($);

than this error occures:

Uncaught TypeError: Cannot read property 'advanced' of undefined

Thanks for your support and great framework!!

BorisMoore commented 8 years ago

http://www.jsviews.com/#node/browserify@jsviews

If jQuery is loaded globally then require('jsviews') will load JsViews (as a jQuery plugin on the global jQuery') and return the jQuery object $. So then when you pass your local $ as parameter you are in fact doing $(Local$);

If you want require('jsviews')($); to work you have to first write global.jQuery = undefined;

For example you could do:

var global$ = global.jQuery;
global.jQuery = undefined;
require('jsviews')(local$);
global.jQuery = global$

That's what I do in this unit test: https://github.com/BorisMoore/jsviews/blob/master/test/browserify/8-unit-tests.js#L15

ViktorHofer commented 8 years ago

Hey Boris,

thanks that helped me a lot!