
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
A tiny library that enables old school MVC, MVVM, MVWhatever approach with React.
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:
export class TodoController {
items = [];
// method receives props passed to <Todo />
$mount({ prop }) {
console.log('Todo: Initialized with ', prop);
}
$unmount() {
console.log('Todo: Destroyed!');
}
toggleDone(index) {
this.items[index].done = !this.items[index].done;
}
addItem(description) {
this.items.push({
description,
done: false,
})
}
}
Than you can use this controller as initialized object in your component:
import { useViewModel } from '../viewmodel';
export function Todo() {
const vm = useViewModel();
// in case you don't want to pollute your business logic with a controlled input
const [description, setDescription] = useState('');
return (
<ul>
<li>
{vm.count}
<button onClick={() => vm.increment()}>Increment</button>
</li>
<li>
<input type="text" value={description} onChange={e => setDescription(e.target.value)} />
<button onClick={() => vm.addItem(description)}>Add</button>
</li>
{vm.items.map((item, index) =>
<li key={index}>
<label>
<input type="checkbox" checked={item.done} onChange={() => vm.toggleDone(index)} /> {item.description}
</label>
</li>
)}
</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):
import { Todo } from './Todo';
import { TodoController } from './TodoController';
import { viewModel } from '../viewmodel';
export default viewModel(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.
FAQs
Library for old school MVVM approach with react
We found that react-vm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.