These are chat archives for canjs/canjs

Nov 2016
Frank Lemanschik
Nov 15 2016 04:49
Alarm: <- some one needs to upgrade jsbin to pro the example don't works :)
Nov 15 2016 08:29
Hello, i am a new in canjs
i have an api in external link and it accept json or xml and would like to connect a model to this external link, how can i do for it works
Viktor Busko
Nov 15 2016 12:51

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?

Gregg Roemhildt
Nov 15 2016 15:35
@Lighttree I've used the subscribe/publish pattern before and initially thought that I would use that same pattern with canjs but I've found canjs's live binding pattern to be much more flexible. For instance, you have a list of users that is an array. With live binding, you can share that list with multiple components. If one component adds a user to the list ie. 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 error event.
Viktor Busko
Nov 15 2016 16:47
@roemhildtg "With live binding, you can share that list with multiple components." I think I can't because for sharing you need to have this data in some shared "scope" and in my case I have 2 separate components that doesn't share same environment from canjs point 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.
Viktor Busko
Nov 15 2016 16:57
I need something like this because not all functionality can use can.js I have a lot of things that use just plain JS and it would be nice to establish some way to work for canjs components with "world outside"
Gregg Roemhildt
Nov 15 2016 17:01
Have you looked into can-route at 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)
Kevin Phillips
Nov 15 2016 17:12
you can also share a model or a map instance between your view models
and put your shared state there