Throttled computed properties

Is there any particular "enyo way" to throttle computed properties?


  • You can suspend notification of changes to observers using the stopNotifications and startNotifications calls on the object that holds the property you're changing. It's useful to use that before changing a lot of values.
  • How would I apply that in a situation such as the following:

    I've got a enyo.ModelController that fetches a model. After fetching, I sync the model controller using modelController.sync(). This sync call notifies the observers for individual attributes on the model. These individual observers are supposed to be notified, because i'm using bindings to bind the value of some of the models' attributes to a variety of components on the screen.

    One of these components has a computed value that requires the values of 6 different attributes. If I silence all notifications for the sake of not triggering the computation many times over (which invokes change to the DOM each time), my other bindings will fail as well.

    My current solution is as follows, which seems adequate, but i thought maybe there's some enyo.job magic i'm not aware of:
        computed: {
            title: [
        bindings: [{
            from: "._computedTitle",
            to: ".$.title.content"
        _computedTitle: undefined,
        _titleComputeTimeout: undefined,
        title: function() {
            var that = this;
            if (this._titleComputeTimeout) {
            this._titleComputeTimeout = setTimeout(function() {
            }, 50);
        computeTitle: function() {
            var computedTitle = /* some computation */
            this.set("_computedTitle", computedTitle);
  • Have you tried the cached parameter for the computed property? Sounds like it would solve your problem.

    Some info in the source code
  • Ooh, that sounds very handy indeed! Enyo is so densely packed with features it keeps surprising me.
Sign In or Register to comment.