DEV Community

Discussion on: I wrote a state management npm - Any State

Collapse
 
joelbonetr profile image
JoelBonetR 🥇 • Edited

Love the initiative! :)

My feedback on it looking at the API:

This set and get methods for items are using array indexes directly which is bad yada yada.

I'd recommend to use nested objects so you can identify pieces of data easily:

const anyState = anystate.set('user', {
  name: 'John',
  age: 30,
  children: [{
      name: 'Bob',
      age: 5,
  }]
});
Enter fullscreen mode Exit fullscreen mode

So then you can

const entireState = anyState.get();
const user = anyState.get('user');
const userChildren = anyState.get('user.children');
Enter fullscreen mode Exit fullscreen mode

For example. This way you can also get rid of createState() because setState will create it if not exists and getItem is no longer necessary.

*Also remember that you need some way to ensure that you can't override a state by redefining it anywhere else

Check this as well to see if it suits this project.

Do you plan a roadmap for AnyState? That would be nice! 👌😁

Looking forward to see how it evolves

Collapse
 
vyquocvu profile image
Vy Quốc Vũ

Thanks @joelbonetr so much!
I very appreciate your advice, i will improve this project day by day.

Collapse
 
joelbonetr profile image
JoelBonetR 🥇

awesome! :)