region-signal
Closed this issue · 2 comments
dancerphil commented
Is your feature request related to a problem? Please describe.
basic
import {createSignal} from 'region-signal';
const signal = createSignal<string>('initialValue');
const handleChange = e => {
signal.value = e.target.value;
};
const Component = () => {
return <input value={signal.value} onChange={handleChange} />;
};
async
import {createSignal} from 'region-signal';
const signal = createSignal<User>();
const loadUser = signal.loadBy(asyncFuncion);
// call loadUser in application lifecycle
loadUser({userId: 1});
const Component = () => {
const value = signal.value;
const loading = signal.loading;
const error = signal.error;
// ...
return <div>{value}</div>;
}
Describe the solution you'd like
/
Describe alternatives you've considered
/
Additional context
/
dancerphil commented
Close since we can not implement useValue(key)
in MappedRegion. (If can, why not a hook?)
The deep reason is that it must not exist a pattern which is isomorphic to function: key => value
to represent value ^ key
.(And also unnecessary.)
dancerphil commented
Maybe we can introduce a new api called signalMap
to fix this:
const signalMap = createSignalMap(() => createSignal(0));
const signal = signalMap(key);
const loadUser = signal.loadBy(asyncFuncion);
// call loadUser in application lifecycle
loadUser({userId: 1});
const Component = () => {
const value = signal.value;
const loading = signal.loading;
const error = signal.error;
// ...
return <div>{value}</div>;
}