These are chat archives for canjs/canjs
Guys, maybe someone could could give me an advice. I have multi page application (
Java based, but it doesn't matter). I would like to create
CanJS components and use them on pages. There is might be case when I have page (not canjs view with stache! lets say
.jsp) with couple of components. For example list of users and component that adds users to this list. Maybe you have good approach how to wire separate components so action in one component will change another?
I have an idea, but not sure how good it will work. I was thinking about using global mediator on each page, so it will work as event system. And if I need "add user to user-list" I will do something like
mediator.dispatch('application:userlist:add', User) inside component that should add users to the list (if I need to add users from any other provider I'll call this as well). And inside "user-list" I will do something like
mediator.subscribe('application:userlist:add', logic). I'll need to add this logic to veiwModel I suppose. Should this work good enough or there is some another better way to do something like this?
this.users.push(new User());, the other components will update accordingly, if the data binding is set up correctly, no need for pub/sub. In other cases, like error throwing I've used canjs's event system to dispatch events and have a parent component listen for an
canjspoint of view. And I don't see how one component can affect another. I'll probably create some fiddle, but the point is that this is like I have canjs components A and B, and they inserted not in some canjs app, but in just html page. And yes you can provide some values as params, and use live binding in scope of one component, but not share something between A and B (its like I would like to affect canjs component outside of canjs). Unless I'm missing something.
can-routeat all? It lets you bind all of your view model's data to a url hash. I've used that for sharing data with a non-canjs library. (I work with dojo/dijit widgets on a regular basis)