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

Mixed approach: Load jQuery statically, and JsRender/JsViews as a Browserify module #295

Closed
daslicht opened this issue Mar 27, 2016 · 5 comments

Comments

@daslicht
Copy link

Hi ,
I tried to implement this approach as described in the documentation and in the node example.
But I still get that jQuery is missing.

Include jQuery in the layout :
https://github.com/daslicht/jsviews-includes/blob/master/app/layout.html#L16

Include the Browserify Bundle:
https://github.com/daslicht/jsviews-includes/blob/master/app/layout.html#L18

Finally include jsrender:
https://github.com/daslicht/jsviews-includes/blob/master/public/index.js#L14

But I still get :

Uncaught TypeError: $.templates is not a function

What do I miss/oversee please?

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

@BorisMoore
Copy link
Owner

It looks as if this may be a bug in my tmplify code. I'll look into it. Meantime you should be able to include jQuery in the client bundle, and it should work OK.

@daslicht
Copy link
Author

ok

@BorisMoore
Copy link
Owner

If you want to try a local fix for this issue, you can go into the node_modules/jsrender folder and change the last line of jsrender.js:

https://github.com/daslicht/jsviews-includes/blob/master/node_modules/jsrender/jsrender.js#L2068

to

return $ || jsr;
}, window || this));

@BorisMoore
Copy link
Owner

Interesting. In fact this bug arose because previously I had the code var global = (0, eval)('this') - which worked fine also in the context of browserify. But I was forced to change that because of BorisMoore/jsviews#323. So I switched to passing in the global parameter, from this - https://github.com/BorisMoore/jsrender/blob/master/jsrender.js#L2068.
(See f984e13#diff-79437e7f72c977b74a2d2d5d75ca518cL16.)

That works in most scenarios, but browserify calls that line of code from a 'compiled function' which has this set to {}. I don't know if I can make browserify use the global context this which will be window, when that code runs in the browser... My fix of window||this is in effect a workaround for this problem...

BorisMoore added a commit to BorisMoore/jsviews.com that referenced this issue Apr 3, 2016
Several new and improved documentation topics:

- http://www.jsviews.com/#views JsRender view hierarchy
- http://www.jsviews.com/#getindex Iterating over arrays: accessing the array index
- http://www.jsviews.com/#contextualparams Contextual parameters
- http://www.jsviews.com/#parentdata Accessing parent data
- http://www.jsviews.com/#apps Building apps
- http://www.jsviews.com/#jsrmodel Data / View Model
- http://www.jsviews.com/#compiletmpl Using templates
- http://www.jsviews.com/#d.templates Registering templates: $.templates()
- http://www.jsviews.com/#helpers Using helpers
- http://www.jsviews.com/#helpersapi Registering helpers: $.views.helpers()
- http://www.jsviews.com/#converters Using converters
- http://www.jsviews.com/#convertersapi Registering converters: $.views.converters()

Unit tests
- Many new unit tests added, especially for Browserify scenarios

Bug fixes

- BorisMoore/jsrender#295 Issue with Browserify when loading
  jQuery statically, and JsRender/JsViews as a Browserify module
BorisMoore added a commit that referenced this issue Apr 3, 2016
Several new and improved documentation topics:

- http://www.jsviews.com/#views JsRender view hierarchy
- http://www.jsviews.com/#getindex Iterating over arrays: accessing the array index
- http://www.jsviews.com/#contextualparams Contextual parameters
- http://www.jsviews.com/#parentdata Accessing parent data
- http://www.jsviews.com/#apps Building apps
- http://www.jsviews.com/#jsrmodel Data / View Model
- http://www.jsviews.com/#compiletmpl Using templates
- http://www.jsviews.com/#d.templates Registering templates: $.templates()
- http://www.jsviews.com/#helpers Using helpers
- http://www.jsviews.com/#helpersapi Registering helpers: $.views.helpers()
- http://www.jsviews.com/#converters Using converters
- http://www.jsviews.com/#convertersapi Registering converters: $.views.converters()

Unit tests
- Many new unit tests added, especially for Browserify scenarios

Bug fixes

- #295 Issue with Browserify when loading
  jQuery statically, and JsRender/JsViews as a Browserify module
@BorisMoore
Copy link
Owner

This has been fixed with commit 75. (v0.9.75)

BorisMoore added a commit to BorisMoore/jsviews that referenced this issue Apr 3, 2016
Several new and improved documentation topics:

- http://www.jsviews.com/#views JsRender view hierarchy
- http://www.jsviews.com/#getindex Iterating over arrays: accessing the array index
- http://www.jsviews.com/#contextualparams Contextual parameters
- http://www.jsviews.com/#parentdata Accessing parent data
- http://www.jsviews.com/#apps Building apps
- http://www.jsviews.com/#jsrmodel Data / View Model
- http://www.jsviews.com/#compiletmpl Using templates
- http://www.jsviews.com/#d.templates Registering templates: $.templates()
- http://www.jsviews.com/#helpers Using helpers
- http://www.jsviews.com/#helpersapi Registering helpers: $.views.helpers()
- http://www.jsviews.com/#converters Using converters
- http://www.jsviews.com/#convertersapi Registering converters: $.views.converters()

Unit tests
- Many new unit tests added, especially for Browserify scenarios

Bug fixes

- BorisMoore/jsrender#295 Issue with Browserify when loading
  jQuery statically, and JsRender/JsViews as a Browserify module
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

2 participants