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

Use dotnetify outside of react components? #30

Closed
dannief opened this issue Jun 15, 2017 · 3 comments
Closed

Use dotnetify outside of react components? #30

dannief opened this issue Jun 15, 2017 · 3 comments

Comments

@dannief
Copy link

dannief commented Jun 15, 2017

All examples that I have seen, demonstrate using dotnetify directly inside react component's getIntialState() function, and it is required to pass the current instance of the component: dotnetify.react.connect(vmName, component)

Is it possible to use dotnetify outside of a react component, so that it may be used with any client-side framework or inside an external service for example? Can we get an instance of a vm and dispatch changes and subscribe to server changes outside of react? Or would it just make sense to use signalR directly in that case?

@dsuryd
Copy link
Owner

dsuryd commented Jun 15, 2017

Yes, it's possible. The API is customized for React, but you can hack it a bit to this:

var myState = {};
dotnetify.react.connect("MyVM", { props: {}}, () => myState, newState => Object.assign(myState, newState) );

@dannief
Copy link
Author

dannief commented Jun 15, 2017

OK. Thanks.

@dannief dannief closed this as completed Jun 15, 2017
@dsuryd dsuryd mentioned this issue Oct 6, 2017
@dsuryd
Copy link
Owner

dsuryd commented Oct 6, 2017

Since v2.0.6-beta, there's a new wrapper API:

let myState = {};
this.vm = dotnetify.connect("MyVM", { 
      getState: () => myState,
      setState: newState => Object.assign(myState, newState)
});

...
this.vm.dispatch({someProp: someValue});

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