How to use the mobservable.props 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-boilerplate / src / todos.js View on Github external
todos[0].completed = true;
// Prints: 'Completed 1 of 2 todo items'

export function addTodo(title) {
	todos.push(mobservable.fromJson({
		title: title,
		completed: false
	}));
}

export function removeTodo(todo) {
	todos.splice(todos.indexOf(todo), 1);
}

/** How to do something async: */
mobservable.props(todos, { isLoading: 0 });

export function loadTodosAsync() {
	todos.isLoading++;
	// mimic something asynchronous
	setTimeout(function() {
		addTodo("Asynchronously created todo");
		addTodo("Another asynchronously created todo");
		todos.isLoading--;
	}, 2000);
}