How to use the mobservable.extras function in mobservable

To help you get started, we’ve selected a few mobservable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mobxjs / mobx-react / test / reactiveComponent.js View on Github external
test.equal(todoListRenderings, 1, "should have rendered list once");
    test.equal(listResult.props.children.length, 2, "list should have two children");
    test.equal(listResult.props.children[0].props.children, "1", "should have correct title");
    test.equal(listResult.props.children[1].length, 1, "list should on item in the list");
    
    var item1$ = shallow(todoItem, listResult.props.children[1][0].props);
    item1$.getRenderOutput();
    test.equal(todoItemRenderings, 1, "item1 should render once");
    test.equal(mobservable.extras.getDNode(store, "todos").observers.length, 1, "observer count on store is not increased");
    test.equal(mobservable.extras.getDNode(store.todos[0], "title").observers.length, 1, "title observers should have increased");

    store.todos[0].title += "a";
    test.equal(todoListRenderings, 1, "should have rendered list once");
    test.equal(todoItemRenderings, 2, "item1 should have rendered twice");
    test.equal(mobservable.extras.getDNode(store, "todos").observers.length, 1, "observers count shouldn't change");
    test.equal(mobservable.extras.getDNode(store.todos[0], "title").observers.length, 1, "title observers should not have increased");
    
    store.todos.push({
        title: "b",
        completed: true
    });

    listResult = list$.getRenderOutput();
    test.equal(listResult.props.children[1].length, 2, "list should two items in in the list");
    
    var item2$ = shallow(todoItem, listResult.props.children[1][1].props);
    item2$.getRenderOutput();
    
    test.equal(todoListRenderings, 2, "should have rendered list twice");
    test.equal(todoItemRenderings, 3, "item2 should have rendered as well"); 
    test.equal(mobservable.extras.getDNode(store.todos[1], "title").observers.length, 1, "title observers should have increased");
    test.equal(mobservable.extras.getDNode(store.todos[1], "completed").observers.length, 0, "completed observers should not have increased");
github mobxjs / mobx-react / test / reactiveComponent.js View on Github external
exports.testNestedRendering = function(test) {
    var list$ = shallow(todoList, { store: store });
    var listResult = list$.getRenderOutput();
    
    test.equal(todoListRenderings, 1, "should have rendered list once");
    test.equal(listResult.props.children.length, 2, "list should have two children");
    test.equal(listResult.props.children[0].props.children, "1", "should have correct title");
    test.equal(listResult.props.children[1].length, 1, "list should on item in the list");
    
    var item1$ = shallow(todoItem, listResult.props.children[1][0].props);
    item1$.getRenderOutput();
    test.equal(todoItemRenderings, 1, "item1 should render once");
    test.equal(mobservable.extras.getDNode(store, "todos").observers.length, 1, "observer count on store is not increased");
    test.equal(mobservable.extras.getDNode(store.todos[0], "title").observers.length, 1, "title observers should have increased");

    store.todos[0].title += "a";
    test.equal(todoListRenderings, 1, "should have rendered list once");
    test.equal(todoItemRenderings, 2, "item1 should have rendered twice");
    test.equal(mobservable.extras.getDNode(store, "todos").observers.length, 1, "observers count shouldn't change");
    test.equal(mobservable.extras.getDNode(store.todos[0], "title").observers.length, 1, "title observers should not have increased");
    
    store.todos.push({
        title: "b",
        completed: true
    });

    listResult = list$.getRenderOutput();
    test.equal(listResult.props.children[1].length, 2, "list should two items in in the list");