Cannot reset computed propety cache


#1

I have controller with computed property. This property caches and i cannot update it.

Builder.PageController = Ember.ObjectController.extend({
    needs: ['layout'],

    mergedStructure: function() {
        'use strict';
        var page = this.get('model.structure');
        var layout = this.get('controllers.layout.model.structure');

        function merge(obj1, obj2) {
            var i = 0;
            var c = 0;
            var pLength = obj1.length;
            var lLength = obj2.length;
            var block, obj;

            for (; i < pLength; i++) {
                if (obj1[i].type === 'block') {
                    block = obj1[i];
                    c = 0;
                    for (; c < lLength; c++) {
                        obj = obj2[c];
                        if (obj.type === block.type && block.name === obj.name) {
                            obj2[c] = block;
                        } else if (obj.children) {
                            merge(page, obj2[c].children);
                        }
                    }
                }
            }
        }

        merge(page, layout);
        return layout;
    }.property('model.structure')
});

My view file

{{#each item in mergedStructure}}
    {{page-structure data=item}}
{{/each}}

I have tried volatile() and it didn’t help. So it works only for the first time when i open the page loc/default/2 (default - layout id), but when i click to another page loc/default/1 my page content doesn’t being change.


#2

Maybe it’s related to model hook in Route, have you provided a model to {{#link-to}}?


#3

Thanks i found the reason. Fix is

var page = this.get('model.structure').slice(0);
var layout = this.get('controllers.layout.model.structure').slice(0);

After the first execution it replaces layout model structure that is why it was always equal. I had to clone these array.