-
Notifications
You must be signed in to change notification settings - Fork 0
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
How to access a viewModel instance? #10
Comments
Being able to pass a viewModel instance to the Extracting from the DOM would only be a somewhat less messy solution for the top level component. For components that aren't calling |
I think you just need to rethink what you are doing here. You almost certainly don't want get the viewModel off the DOM, this is React, the DOM has been extracted away. If you needed access to the But for your use case, what you want to do is but the import AppHome from './app.jsx';
import compute from 'can-compute';
export const message = compute('Hello, Feathers!');
export const ViewModel = DefineMap.extend({
get message() {
return message();
},
changeMessage () {
message('Hello, Marshall!')
}
});
const AppContainer = connect(ViewModel, AppHome); ...now you could export import { message } from '/components/AppContainer'; ...or more likely you would have some model or something seperate that had message in it, that you would export and pass around. RE: routing Let me know if you want to discuss more or if this issue can be closed. |
Very nice. Yeah, I figured out the routing demo after I posted this, which works wonderfully. Between that and the examples you've posted, there's just enough flexibility to do pretty much anything👏🎉 |
In the following example, I create a
ViewModel
andconnect
it to an imported AppHome component.Suppose I want to pass
message
in the example to a component several levels deep. I'm passing theViewModel
constructor to theconnect
function, but how do I export the actualviewModel
instance to make it available elsewhere? This is needed to link up can-route to a viewModel:Is there a way to extract the
viewModel
once its component has been rendered to the DOM?The text was updated successfully, but these errors were encountered: