-
Notifications
You must be signed in to change notification settings - Fork 200
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 apply DRY principles in example code #265
Comments
You can make a function that returns both new data and a new view, like this: const updateData = dataNew => ({
data: dataNew,
view: (<Todos data={dataNew}/>)
});
const updateTodo = ({ data, view }) => updateData({
...data,
todo: view.target.value
});
const createTodo = ({ data, view }) => updateData({
todo: "",
todos: [...data.todos, data.todo]
});
const removeTodo = index => ({ data, view }) => updateData({
...data,
todos: data.todos.filter(
(todo, todoIndex) =>
todoIndex !== index
)
}); |
Nice, thanks for the info. I thought you had some shortcuts utility functions for this kind of repetitive code. |
No problem. Utility functions for things like this usually end up being too specific. For example, this wouldn't really work if you were using more drivers (such as |
In the examples for the main website there's the TODO App. How can one use DRY principles for removing the duplicated code?
https://kbrsh.github.io/moon/play
The text was updated successfully, but these errors were encountered: