cferdinandi / reef

A lightweight library for creating reactive, state-based components and UI.

Home Page:https://reefjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add getter methods to store() object

cferdinandi opened this issue · comments

Is it worth having getter methods on the store() object that can be used to get and modify data without triggering a signal event?

let count = store(0, {
  increase (num) {
    num++;
  },
  decrease (num) {
      num--;
  }
}, {
  getDouble (num) {
     return num * 2;
  }
});

While you can technically use actions this way already, each one emits a signal event and triggers a reactive UI update on components that use the object data.

With getter methods, the data would remain immutable and simply provide a useful way to bind data manipulations to the store() itself.

Of course, this same thing can be handled today with helper methods as well...

let count = store(0, {
  increase (num) {
    num++;
  },
  decrease (num) {
      num--;
  }
});

function getDouble (num) {
  return num * 2;
}

getDouble(count.value);

As a result, I'm not sure getter methods add all that much value, but they DO increase the complexity of the project.