Hi I’m new to canjs, I have tried the examples in the chat guide in JsBin and they work fine. The problem comes when I try to run them in my own development environment.
I’ve tried many ways:
Using webpack with es6, stage-2 presets enabled, and requiring the template with raw-loader.
Using webpack without presets but requiring the template with raw-loader
Using webpack without presets but the template as a string pasted inside the js file.
var DefineMap = require(‘can-define/map/map’);
var stache = require(‘can-stache’);
template = stache(require(‘…/src/canjs/template.hbs’));
var frag = template(appVM);
document.body.appendChild(frag);
appVM.addExcitement(); //this works
document.getElementById(‘click-this’).click(); //this doesn’t, neither clicking the element in the browser.
Webpack version is 1.14.0.
Browser : Chrome 55.0.2883.87 m.
I can call the ViewModel method and the {{message}} is modified in the view. But when I click the h1 the click method is not called.
appVM.addExciment() works fine, the view updates with the new message value. The problem is with the click event that doesn’t call the addExciment method.
It looks like the global version of can used in the JS Bin is working correctly, but using the can-* modules isn’t, so we’re working through that bug right now. I’m hoping to have another update for you soon.
The issue is that the binding syntax ($click) is part of the can-stache-bindings module, so you’ll need to install it and require it for the click to work correctly.
At least when using live bindings without importing can-stache-bindings It could throw an informative warning in development mode. Or possibly could be imported dynamically calling for example stache.useLiveBindings() before any stache() call that uses live bindings.
I don’t see the distinction between live bindings and other types of bindings. There are a few types of bindings I can see existing:
TextNode
Attributes
Properties
ViewModel which is really just a subset of property bindings.
Events
These are the only things that exist in HTML/DOM. can-stache’s live bindings are really just TextNode bindings. I don’t understand the case where you would want stache’s TextNode bindings but not its attribute bindings. I would think that if you don’t want any one particular type of bindings you would want to replace the language all together. In my templating engine I don’t make a distinction between TextNode and other types. Would like to hear more about the use case here.
Ah, ok, so then really the issue here is that Stache is a text manipulation language, not an HTML manipulation language. In that context I think the distinction makes sense. can-stache is about manipulating text that will be (eventually) serialized into DOM Nodes. can-stache-bindings is about manipulating DOM Nodes.
Maybe can-stache-bindings should be renamed then? It is not necessarily tied to can-stache in any way that I can think of. can-view-target is what calls the callbacks. Maybe something like can-element-bindings?
Hi @Arjen_Haayman, could you check with the latest version of can-stache-bindings (3.9.1)? Are you using Browserify, StealJS, or webpack for module loading?