1.1.55 • Published 3 years ago
react-clean-use-case v1.1.55
React adapters for clean use cases
import React, { FunctionComponent } from 'react';
import { Each, useObservables } from 'reactivex-react';
import {
DeleteTodo,
FilterTodoList,
getRandomString,
GetTodoFilters,
GetTodoList,
IAddTodo,
IAddTodoActionKey,
repeat,
TodoNotificationSaga,
} from '../../../../application';
import { useAction, useCommand, useQuery, useSaga } from 'react-clean-use-case';
import { Button, Panel } from 'web/ui';
export const TodoList: FunctionComponent = () => {
useSaga(TodoNotificationSaga);
const filterTodos = useCommand(FilterTodoList);
const filter$ = useQuery(GetTodoFilters, (q) => q.create());
const todoList$ = useQuery(GetTodoList, (m) => m.create());
const addTodo = useAction<IAddTodo>(IAddTodoActionKey);
const deleteTodo = useCommand(DeleteTodo);
const $ = useObservables();
return (
<Panel>
<Button
onClick={() =>
addTodo.dispatch({
id: getRandomString(10),
title: 'Hey',
message: 'Hou',
priority: Math.round((Math.random() * 10) % 5),
})
}
>
Add
</Button>
<select
defaultValue={$(filter$)!.minPriority}
onChange={({ target }) => filterTodos.execute({ minPriority: parseInt(target.value) })}
>
{repeat(6).map((i) => (
<option key={i} value={i}>
{i}
</option>
))}
</select>
<select
defaultValue={$(filter$)!.maxPriority}
onChange={({ target }) => filterTodos.execute({ maxPriority: parseInt(target.value) })}
>
{repeat(6).map((i) => (
<option key={i} value={i}>
{i}
</option>
))}
</select>
<ul>
<Each obs$={todoList$}>
{({ id, title, message, priority }) => (
<li key={id}>
{title} - {message} - {priority}
<button className="btn btn-danger" onClick={() => deleteTodo.execute(id)}>
Delete
</button>
</li>
)}
</Each>
</ul>
</Panel>
);
};
1.1.55
3 years ago
1.1.54
3 years ago
1.1.38
3 years ago
1.1.37
3 years ago
1.1.36
3 years ago
1.1.35
3 years ago
1.1.39
3 years ago
1.1.41
3 years ago
1.1.40
3 years ago
1.1.45
3 years ago
1.1.44
3 years ago
1.1.42
3 years ago
1.1.49
3 years ago
1.1.48
3 years ago
1.1.47
3 years ago
1.1.46
3 years ago
1.1.50
3 years ago
1.1.32
3 years ago
1.1.31
3 years ago
1.1.29
4 years ago
1.1.28
4 years ago
1.1.9
4 years ago
1.1.12
4 years ago
1.1.11
4 years ago
1.1.10
4 years ago
1.1.16
4 years ago
1.1.15
4 years ago
1.1.14
4 years ago
1.1.13
4 years ago
1.1.19
4 years ago
1.1.18
4 years ago
1.1.17
4 years ago
1.1.23
4 years ago
1.1.22
4 years ago
1.1.21
4 years ago
1.1.20
4 years ago
1.1.27
4 years ago
1.1.26
4 years ago
1.1.25
4 years ago
1.1.24
4 years ago
1.1.1
4 years ago
1.1.8
4 years ago
1.1.7
4 years ago
1.1.6
4 years ago
1.1.5
4 years ago
1.1.4
4 years ago
1.1.3
4 years ago
1.1.2
4 years ago
1.1.0
4 years ago
1.0.22
4 years ago
1.0.21
4 years ago
1.0.20
4 years ago
1.0.26
4 years ago
1.0.25
4 years ago
1.0.24
4 years ago
1.0.16
4 years ago
1.0.14
4 years ago
1.0.13
4 years ago
1.0.12
4 years ago
1.0.11
4 years ago
1.0.5
4 years ago
1.0.4
4 years ago
1.0.3
4 years ago
1.0.2
4 years ago
1.0.1
4 years ago