Skip to content
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

Type based signals #11

Open
Machy8 opened this issue Aug 18, 2023 · 0 comments
Open

Type based signals #11

Machy8 opened this issue Aug 18, 2023 · 0 comments

Comments

@Machy8
Copy link
Contributor

Machy8 commented Aug 18, 2023

  • This could reduce the amount of boilerplate while working with signals
  • Arrays are often mutated, items removed and added, to/from the beginning/end, sorted
  • Numbers are often incremented, decremented or modified by some number
  • Object keys are often added/removed and sorted

This feature would be opt-out and would work as follows:

const number = signal(0);

// Instead of this
number.set(number() + 1);

// It would detect a number type and would expose the following function "sum" for example
number.sum(1);
number.sum(-1)

// For array
const items = signal([1,2,3]);

items.push(1);
items.pop();
items.unshift();

Similar like vue.
https://vuejs.org/guide/essentials/list.html#array-change-detection

TODO

  • Should it be accssible instantly, like items.push() or after get items().push()
  • Should these methods be accessible in the core or in signalize/typed-signals package?
  • Arrays methods?: Probably like Vue? https://vuejs.org/guide/essentials/list.html#array-change-detection
  • Objects methods?
  • Numbers methods?: sum
  • Strings methods?: append, prepend
  • Boolean methods?: negate
  • Map?
  • Set?
  • Maybe only mention in the docs on how to do so? Because there can be various signal types and various ways to solve this. Angular has it in he core. If developer doesn't use it. It only increases the size of the framework.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant