A tiny library that enables old school MVC, MVVM, MVWhatever approach with React.
Usage
Given that you have a component that needs to be smart called <Todo />
. You can write it's business logic in plain ES6 class like this:
items = ; // method receives props passed to <Todo /> console; console; { thisitemsindexdone = !thisitemsindexdone; } { thisitems }
Than you can use this controller as initialized object in your component:
import useViewModel from '../viewmodel'; { const vm = ; // in case you don't want to pollute your business logic with a controlled input const description setDescription = ; return <ul> <li> vmcount <button =>Increment</button> </li> <li> <input ="text" = = /> <button =>Add</button> </li> vmitems </ul> ;}
You only have to pair the component and the controller to create a so called viewModel (this might be not how it's called at all, i am still confused):
;;; Todo TodoController;
All the changes on the controller instance are triggering rerendering on the react component.
Wondering how it works? Take a look at the code. It's simple and very ugly.
DISCLAIMER: This is just a prototype of an idea and is implemented in a very non-efficient way. It most probably does not cover a lot of use cases as it was not tested on large scale apps. If you think this is a terrible idea, I'd happily like to know why.