Ale.js

Proxy

Start

In 1.0.0, we abolished the debug parameter and added a function similar to the proxy parameter, but with a slightly different way of using it:

1
2
3
4
5
proxy: {
setter: function(obj){
console.log(obj);
}
}

The proxy parameter supports the setter and getter functions to proxy data settings and fetches. You can add proxy when the component is defined, or you can add it dynamically when rendering.

setter

The setter parameter needs to be a function and needs to receive one parameter:

1
2
3
setter: function(obj){
/* ... */
}

The obj parameter has the following key values:

  • type[Type of the data. Normal stands for normal data, static stands for static data.
  • key [name of the data]
  • val [new value set]
  • preventUpdating [function, call to prevent component view update, but does not prevent component data value update]

At the same time, you need to use the return keyword to return the new value set, otherwise the component data value will be updated to undefined:

1
2
3
4
5
6
7
setter: function(obj){
return obj.val;

/* Or you can return the value you set.
return "Don't let you update the data!";
*/
}

Of course, you can also use the preventUpdating function to prevent component updates from being updated, but you can’t prevent component data values from being updated (can be blocked by return):

1
2
3
4
setter: function(obj){
obj.preventUpdating();
return obj.val;
}

getter

Similarly, the getter parameter needs to be a function and also needs to receive a parameter.

1
2
3
getter: function(obj){
/* ... */
}

The obj parameter also has the following key values:

  • type[Type of the data. Normal stands for normal data, static stands for static data.
  • key [name of the data]
  • val [value obtained]
  • preventUpdating [function, call to prevent component view update, but does not prevent component data value update] [invalid! Because getters don’t cause view updates! 】

Found some errors? Edit on Github!