Draft: signal prototypes by hoebbelsB · Pull Request #1523 · rx-angular/rx-angular

Description

https://hackmd.io/gf5D1kC0RVKfDrJZXY-V0Q

State

  • connect accepts signals
  • get computed from state
  • read signal from state
  • create effect from state
// component state
private state = inject<RxState<{ todos: Todo[]; foo: string}>>(RxState);

Connect a signal

const todos: Signal<Todo[]> = signal(todoData);
this.state.connect('todos', todos);

Computed from state

// takes a function that gets each property of the state as `Signal<T[K]>`.
// in this case, todos will be `Signal<Todo[]>`

const count: Signal<number> = this.state.computed(({ todos }) => {
    return todos().length;
});

Signal from state

const todosSignal: Signal<Todo[]> = this.state.signal('todos');

Effect from state

const _effect: Effect = this.state.effect(({ todos }) => {
   if (todos().length > 20) {
      console.log('something was added');
    }
});

To be discussed

  • proxy object for easier access

Template

  • rxLet accepts signal
  • rxFor accepts signal
  • rxIf accepts signal
  • push pipe accepts signal

To be discussed

  • introduce transition like API (as in react concurrent mode) to have a scheduled signal using RxRenderStrategies internally?