V
V
Vitaly2017-06-13 19:06:28
Node.js
Vitaly, 2017-06-13 19:06:28

Is there a module to create reactive methods?

We need the following module. The input is an object method and a callback. The method code is analyzed, browsers are hung on the properties used in the method, when any of these properties change, the value of the method is recalculated and the result is passed to the callback.
Example:

class People {
  constructor() {
    this.firstName = 'noname';
    this.lastName = 'Man';
  }

  name() {
    return this.firstName + ' ' + this.lastName;
  }

  hello() {
    return `Hello, ${this.name()}!`;
  }
}

const people = new People();

//вешаем обозреватель на hello
pseudo_observable(people, 'hello', (value) => console.log(value));

people.firstName = 'Cool';
//console.log => Hello, Cool Man!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
Coder321, 2017-06-13
@Coder321

https://www.npmjs.com/package/rxjs I think it will help you.

I
Ivan, 2017-06-13
@LiguidCool

Why do React and Redux immediately come to my mind?

K
Konstantin Kitmanov, 2017-06-14
@k12th

There are links to reactive libs with an explanation of the difference: https://habrahabr.ru/post/317360/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question