-
Notifications
You must be signed in to change notification settings - Fork 9
/
05s-the-session.md.erb
157 lines (107 loc) · 1.81 KB
/
05s-the-session.md.erb
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
---
title: The Session
slug: the-session
date: 0005/01/02
number: 5.5
sidebar: true
contents: Learn about the Meteor Session|Learn about the autorun function|Learn about Hot Code Reload
paragraphs: 33
---
////
////
////
### The Meteor Session
////
////
////
### Changing the Session
////
~~~js
❯ Session.set('pageTitle', 'A different title');
~~~
<%= caption "Browser console" %>
////
////
~~~html
<header class="navbar">
<div class="navbar-inner">
<a class="brand" href="{{pathFor 'postsList'}}">{{pageTitle}}</a>
</div>
</header>
~~~
<%= caption "client/views/application/layout.html"%>
~~~js
Template.layout.helpers({
pageTitle: function() { return Session.get('pageTitle'); }
});
~~~
<%= caption "client/views/application/layout.js"%>
////
////
~~~js
❯ Session.set('pageTitle', 'A brand new title');
~~~
<%= caption "Browser console" %>
////
<% note do %>
### Identical Changes
////
<% end %>
### Introducing Autorun
////
////
~~~js
helloWorld = function() {
alert(Session.get('message'));
}
~~~
////
////
////
~~~js
❯ Deps.autorun( function() { console.log('Value is: ' + Session.get('pageTitle')); } );
Value is: A brand new title
~~~
<%= caption "Browser console" %>
////
~~~js
❯ Session.set('pageTitle', 'Yet another value');
Value is: Yet another value
~~~
<%= caption "Browser console" %>
////
////
~~~js
Deps.autorun(function() {
alert(Session.get('message'));
});
~~~
////
### Hot Code Reload
////
////
////
~~~js
❯ Session.set('pageTitle', 'A brand new title');
❯ Session.get('pageTitle');
'A brand new title'
~~~
<%= caption "Browser console" %>
////
~~~js
❯ Session.get('pageTitle');
'A brand new title'
~~~
<%= caption "Browser console" %>
////
////
////
~~~js
❯ Session.get('pageTitle');
null
~~~
<%= caption "Browser console" %>
////
////
1. ////
2. ////