<commit_before>declare var window: any;

import TestRunner from '../TestRunner';
import Graph from '../../../src/graph/Graph';
import Cascade, {VirtualNode} from '../../../src/cascade/Cascade';

class ViewModel {
    runs: number = 0;
    info: string;
    constructor() {
        Graph.createObservable(this, 'info', 'test');
    }
}

interface ParentComponentProperties {
    id: string;
    info: string;
}

class ParentComponent extends VirtualNode<ParentComponentProperties> {
    viewModel: ViewModel;
    constructor(type: string, properties?: ParentComponentProperties, ...children: (VirtualNode<any> | string)[]) {
        super(type, properties, ...children);
        this.viewModel = new ViewModel();
        window.viewModel = this.viewModel;
    }
    render() {
        return (
            <div id="parent">
                <CustomComponent id="child" info={this.viewModel.info}>text</CustomComponent>
            </div>
        );
    }
}

interface CustomComponentProperties {
    id: string;
    info: string;
}

class CustomComponent extends VirtualNode<CustomComponentProperties> {
    render() {
        return (
            <div id={this.properties.id}>Custom Component - {this.properties.info}</div>
        )
    }
}

TestRunner.test({
    name: 'VirtualNodes can be used to create Components.',
    test: function(input, callback: any) {
        var root = (
            <ParentComponent />
        );
        root._graph.observables.element.subscribe(function(value) {
            console.log(value);
        });
        window.root = root;
        document.body.appendChild(root.element);
        callback(root.element);
    },
    assert: function(result, callback) {
        var child = result.querySelector('#child');
        callback(!!child);
    }
});<commit_msg>Refactored test8.<commit_after>declare var window: any;

import TestRunner from '../TestRunner';
import Graph from '../../../src/graph/Graph';
import Cascade, {VirtualNode} from '../../../src/cascade/Cascade';

class ViewModel {
    runs: number = 0;
    info: string;
    constructor() {
        Graph.createObservable(this, 'info', 'test');
    }
}

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

class ParentComponent extends VirtualNode<ParentComponentProperties> {
    constructor(type: string, properties?: ParentComponentProperties, ...children: (VirtualNode<any> | string)[]) {
        super(type, properties, ...children);
    }
    render() {
        return (
            <div id="parent">
                <CustomComponent id="child" info={this.properties.viewModel.info}>text</CustomComponent>
            </div>
        );
    }
}

interface CustomComponentProperties {
    id: string;
    info: string;
}

class CustomComponent extends VirtualNode<CustomComponentProperties> {
    render() {
        return (
            <div id={this.properties.id}>Custom Component - {this.properties.info}</div>
        )
    }
}

TestRunner.test({
    name: 'VirtualNodes can be used to create Components.',
    test: function(input, callback: any) {
        var viewModel = new ViewModel();
        window.viewModel = viewModel;
        var root = (
            <ParentComponent viewModel={viewModel} />
        );
        root._graph.observables.element.subscribe(function(value) {
            console.log(value);
        });
        window.root = root;
        document.body.appendChild(root.element);
        callback(root.element);
    },
    assert: function(result, callback) {
        var child = result.querySelector('#child');
        callback(!!child);
    }
});
{'fraction_non_alphanumeric': 0.13564493758668517, 'fraction_numerical': 0.0008321775312066575, 'mean_word_length': 2.5773809523809526, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '1277551', 'n_tokens_mistral': 976, 'n_tokens_neox': 977, 'n_words': 217}