<commit_before>import TestRunner from '../TestRunner';
import Cascade, {Component, observable, array} from '../../../scripts/modules/Cascade';

class ViewModel {
    runsA: number = 0;
    runsB: number = 0;
    @observable a: string = 'a';
    @array list: number[] = [1, 2, 3, 4];
}

interface IParentProperties {
    viewModel: ViewModel;
}

class Parent extends Component<IParentProperties> {
    render() {
        this.properties.viewModel.runsA++;
        return (
            <Child id="child" viewModel={this.properties.viewModel} />
        );
    }
}

interface IChildProperties {
    id: string;
    viewModel: ViewModel;
}

class Child extends Component<IChildProperties> {
    render() {
        this.properties.viewModel.runsB++;
        return (
            <ul>
                {this.properties.viewModel.list.map(item => <li>{item}</li>)}
            </ul>
        );
    }
}

TestRunner.test({
    name: 'ViewModels update directly nested Components',
    test: function(input, callback: any) {
        var viewModel = new ViewModel();
        var container = document.createElement('div');
        document.body.appendChild(container);
        Cascade.render(container, <Parent viewModel={viewModel} />);
        setTimeout(function() {
            viewModel.list.push(5);
            setTimeout(function() {
                callback({
                    length: container.querySelectorAll('li').length,
                    runsA: viewModel.runsA,
                    runsB: viewModel.runsB
                });
            }, 20);
        }, 1);
    },
    assert: function(result, callback) {
        callback(result.runsA === 1 && result.runsB === 2 && result.length === 5);
    }
});
<commit_msg>Removed output.<commit_after>import TestRunner from '../TestRunner';
import Cascade, {Component, observable, array} from '../../../scripts/modules/Cascade';

class ViewModel {
    runsA: number = 0;
    runsB: number = 0;
    @observable a: string = 'a';
    @array list: number[] = [1, 2, 3, 4];
}

interface IParentProperties {
    viewModel: ViewModel;
}

class Parent extends Component<IParentProperties> {
    render() {
        this.properties.viewModel.runsA++;
        return (
            <Child id="child" viewModel={this.properties.viewModel} />
        );
    }
}

interface IChildProperties {
    id: string;
    viewModel: ViewModel;
}

class Child extends Component<IChildProperties> {
    render() {
        this.properties.viewModel.runsB++;
        return (
            <ul>
                {this.properties.viewModel.list.map(item => <li>{item}</li>)}
            </ul>
        );
    }
}

TestRunner.test({
    name: 'ViewModels update directly nested Components',
    test: function(input, callback: any) {
        var viewModel = new ViewModel();
        var container = document.createElement('div');
        //document.body.appendChild(container);
        Cascade.render(container, <Parent viewModel={viewModel} />);
        setTimeout(function() {
            viewModel.list.push(5);
            setTimeout(function() {
                callback({
                    length: container.querySelectorAll('li').length,
                    runsA: viewModel.runsA,
                    runsB: viewModel.runsB
                });
            }, 20);
        }, 1);
    },
    assert: function(result, callback) {
        callback(result.runsA === 1 && result.runsB === 2 && result.length === 5);
    }
});

{'fraction_non_alphanumeric': 0.13966318234610917, 'fraction_numerical': 0.007549361207897794, 'mean_word_length': 2.151875571820677, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2989598', 'n_tokens_mistral': 996, 'n_tokens_neox': 975, 'n_words': 209}