-
Notifications
You must be signed in to change notification settings - Fork 0
/
reactivity.js
36 lines (29 loc) · 1.01 KB
/
reactivity.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
$(function() {
autorun(function() {
console.log('First username', reactiveStorage.get('username'));
console.log('First userid', reactiveStorage.get('userid'));
});
autorun(function() {
console.log('Second username', reactiveStorage.get('username'));
});
reactiveStorage.set('username', 'Ivan');
reactiveStorage.set('users', [{
username: 'Ivan'
}]);
//example with dynamyc array -> dynamic list
var $users = $('#users');
autorun(function() {
_.each(reactiveStorage.get('users'), function(user) {
$users.html(template('#user', user));
});
});
autorun(function(){
$.get('api.php', {id: reactiveStorage.get('userid')}, function(response){
console.log('Ajax loaded', response.data);
$('#userFromAjax .user').html(template('#user', response.data));
}, 'json');
});
$('a').click(function(){
reactiveStorage.set('userid', $(this).attr('value'));
});
});