/
sfjs.html
1000 lines (834 loc) · 27.1 KB
/
sfjs.html
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html>
<head>
<title>StackMob - Adding a Backend to your JS App</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="http://static.stackmob.com/js/json2-min.js"></script>
<script type="text/javascript" src="http://static.stackmob.com/js/underscore-1.3.3-min.js"></script>
<script type="text/javascript" src="http://static.stackmob.com/js/backbone-0.9.2-min.js"></script>
<script type="text/javascript" src="http://static.stackmob.com/js/stackmob-js-0.2.1-min.js"></script>
<script type="text/javascript" src="http://static.stackmob.com/resources/js/jsonFormatter-0.1.0-min.js"></script>
<script type="text/javascript" src="stackmob-debug.js"></script>
<!-- Include required JS files -->
<script type="text/javascript" src="../syntaxhighlighter/scripts/shCore.js"></script>
<!--
At least one brush, here we choose JS. You need to include a brush for every
language you want to highlight
-->
<script type="text/javascript" src="../syntaxhighlighter/scripts/shBrushJScript.js"></script>
<script type="text/javascript" src="../syntaxhighlighter/scripts/shBrushXml.js"></script>
<script type="text/javascript" src="../syntaxhighlighter/scripts/shBrushJava.js"></script>
<!-- Include *at least* the core style and default theme -->
<link href="../syntaxhighlighter/styles/shCoreMidnight.css" rel="stylesheet" type="text/css" />
<link href="../syntaxhighlighter/styles/shThemeMidnight.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.syntaxhighlighter {
margin: 0px !important; padding-top: 15px; padding-bottom: 15px;
border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px;
}
</style>
<script type="text/javascript">
StackMob.init({
appName: 'javascript',
clientSubdomain: 'stackmob',
apiVersion: 0
});
var Todo = StackMob.Model.extend({
schemaName: 'todo'
});
var Todos = StackMob.Collection.extend({
model: Todo
});
$(document).ready(function() {
SyntaxHighlighter.config.tagName = 'code';
SyntaxHighlighter.config.toolbar = false;
SyntaxHighlighter.all();
Reveal.addEventListener('stampede', function() {
$('#stampede').attr('src', 'http://dl.dropbox.com/u/77348001/stampede.gif');
});
});
</script>
<link rel="stylesheet" href="../reveal.js/css/reset.css">
<link rel="stylesheet" href="../reveal.js/css/main.css">
<style type="text/css" media="screen">
.button, .button a
{
background: #98be47;
background: linear-gradient(top, #a8cf43, #98be47);
background: -moz-linear-gradient(top, #a8cf43, #98be47);
background: -ms-linear-gradient(top, #a8cf43, #98be47);
background: -o-linear-gradient(top, #a8cf43, #98be47);
background: -webkit-linear-gradient(top, #a8cf43, #98be47);
border: 1px solid #8cac42;
border-bottom-color: #7b9b36;
border-radius: 4px;
border-top-color: #94b146;
box-shadow: 0 2px 2px rgba(0, 0, 0, .2), inset 0 1px 0 rgba(255, 255, 255, .5);
color: #fff !important;
cursor: pointer;
font-family: "Helvetica Neue", Arial, sans-serif;
font-size: 26px;
font-weight: bold;
moz-border-radius: 4px;
moz-box-shadow: 0 2px 2px rgba(0, 0, 0, .2), inset 0 1px 0 rgba(255, 255, 255, .5);
ms-border-radius: 4px;
ms-box-shadow: 0 2px 2px rgba(0, 0, 0, .2), inset 0 1px 0 rgba(255, 255, 255, .5);
o-border-radius: 4px;
o-box-shadow: 0 2px 2px rgba(0, 0, 0, .2), inset 0 1px 0 rgba(255, 255, 255, .5);
padding: 6px 14px;
text-decoration: none;
text-shadow: 0 -1px 0 rgba(0, 0, 0, .4);
webkit-border-radius: 4px;
webkit-box-shadow: 0 2px 2px rgba(0, 0, 0, .2), inset 0 1px 0 rgba(255, 255, 255, .5);
}
.button:hover, .button a:hover
{
background: #67a215;
background: linear-gradient(top, #9dbf46, #67a215);
background: -moz-linear-gradient(top, #9dbf46, #67a215);
background: -ms-linear-gradient(top, #9dbf46, #67a215);
background: -o-linear-gradient(top, #9dbf46, #67a215);
background: -webkit-linear-gradient(top, #9dbf46, #67a215);
border: 1px solid #699631;
border-bottom-color: #457119;
border-top-color: #6d9e34;
color: rgba(250, 250, 250, .96);
text-decoration: none;
text-shadow: 0 -1px 0 rgba(0, 0, 0, .8);
}
.button:active, .button a:active
{
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5);
moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5);
ms-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5);
o-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5);
padding: 4px 14px 7px;
webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5);
}
.button.blue, .button.blue a
{
background: #6bbad7;
background: linear-gradient(top, #76cced, #6bbad7);
background: -moz-linear-gradient(top, #76cced, #6bbad7);
background: -ms-linear-gradient(top, #76cced, #6bbad7);
background: -o-linear-gradient(top, #76cced, #6bbad7);
background: -webkit-linear-gradient(top, #76cced, #6bbad7);
border: 1px solid #4ca8ca;
border-bottom-color: #4c9bb9;
border-top-color: #4cb2da;
}
.button.blue:hover, .button.blue a:hover
{
background: #2c9cc6;
background: linear-gradient(top, #3cb7e5, #2c9cc6);
background: -moz-linear-gradient(top, #3cb7e5, #2c9cc6);
background: -ms-linear-gradient(top, #3cb7e5, #2c9cc6);
background: -o-linear-gradient(top, #3cb7e5, #2c9cc6);
background: -webkit-linear-gradient(top, #3cb7e5, #2c9cc6);
border: 1px solid #0083b4;
border-bottom-color: #00709b;
border-top-color: #0092ca;
}
#stackmoblogo {
position: fixed;
top: 20px;
left: 20px;
}
</style>
</head>
<body>
<div id="stackmoblogo"><img src="../images/stackmob_logo.png"/></div>
<div id="reveal">
<div class="state-background"></div>
<div class="slides">
<section>
<h2>Adding a Server-Side Backend to your JS-powered App</h2>
<h3 class="inverted">StackMob & JavaScript</h3>
<p><span style="font-size: 24px;">(uses Backbone.js)</span></p>
<p style="margin-top: 100px;">
<p><a href="http://www.stackmob.com" target="_blank">stackmob.com</a> | <a href="http://www.twitter.com/stackmob">@stackmob</a></p>
<p>Erick Tai | <a href="http://www.twitter.com/ericktai" target="_blank">@ericktai</a></p>
</p>
</section>
<section>
<h2>@ericktai</h2>
<h3>Erick Tai</h3>
<p><a href="http://www.stackmob.com"><img src="../images/stackmob_logo.png"/></a></p>
</section>
<section>
<h2>Development: Before</h2>
<p>
<img src="../images/1stgen.png"/>
</p>
</section>
<section>
<h2>Development: Better</h2>
<p>
<img src="../images/2ndgen.png"/>
</p>
</section>
<section>
<h2>Development: Today</h2>
<img src ="../images/3rdGen.png" alt="StackMob Diagram"/>
</section>
<section>
<h2>Development: Today continued</h2>
<p>
<p><img src="../images/f_logo.png"/>
<img src="../images/twitter_logo.png"/></p>
</p>
</section>
<section>
<h2>This. But for you.</h2>
<p>This isn't just for Facebook, Twitter, or the big guys.</p>
<p>This is for you.</p>
<p><img width="400px" src="../images/stackmob_logo.png"/></p>
</section>
<section>
<h2>Backend Services</h2>
<ul>
<li>User Authentication</li>
<li>Datastore</li>
<li>Security</li>
<li>GeoSpatial</li>
<li>Push</li>
<li>Hosting</li>
<li>Social Integration</li>
<li>Custom Server Side Code</li>
<li>Analytics</li>
<li>...</li>
</ul>
</section>
<section>
<h2>StackMob: Who are we?</h2>
<ul>
<li>Mobile Backend Platform</li>
<li>Lowering barrier of entry</li>
<li>We handle backend so you can do frontend.</li>
<li>Giving everyone access to "big company" backend power</li>
<li>Develop. Scale. Analytics. Revisioning.</li>
</ul>
</section>
<section>
<h2>StackMob: Who uses us?</h2>
<p>We've powered apps:</p>
<ul>
<li>Featured in the AppStore</li>
<li>Top 20 in the AppStore</li>
<li>TechCrunch Disrupt</li>
<li>SXSW</li>
<li>Won Startup Weekend</li>
<li>Atari</li>
</ul>
<p>Games, Enterprise Apps, Social... </p>
<p>iOS, Android, JavaScript, Ruby, PHP, Python, Java</p>
</section>
<section>
<h2>Backend via JavaScript</h2>
<ul>
<li>Services via REST API: → URL via HTTP Request</li>
<li>Secure it: OAuth</li>
<li>Connect via AJAX</li>
<li>Extended Backbone.js Models</li>
</ul>
</section>
<section>
<h2>REST API</h2>
<p>Accessible from any platform</p>
<pre><code class="brush: xml">
http://api.mob1.stackmob.com/user
../user/login
../todo
../yourcustommethod
</code></pre>
</section>
<section>
<h2>Uses Backbone.js</h2>
Backbone Files:
<pre><code class="brush: xml;">
http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js
http://static.stackmob.com/js/json2-min.js
http://static.stackmob.com/js/underscore-1.3.3-min.js
http://static.stackmob.com/js/backbone-0.9.2-min.js
</code></pre>
</section>
<section>
<h2>Add StackMob JS</h2>
<pre><code class="brush: xml; highlight: [5]">
http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js
http://static.stackmob.com/js/json2-min.js
http://static.stackmob.com/js/underscore-1.3.3-min.js
http://static.stackmob.com/js/backbone-0.9.2-min.js
http://static.stackmob.com/js/stackmob-js-0.2.1-min.js
</code></pre>
</section>
<!--
<section>
<h2>Extended BackBone.js</h2>
<pre><code class="brush: javascript">
StackMob.Model = BackBone.Model.extend({
...
sync: function(method, model, options) { ... },
...
});
StackMob.Collection = BackBone.Collection.extend({
...
});
</code></pre>
</section>
<section>
<h2>Overrode sync method</h2>
<pre><code class="brush: javascript;">
StackMob.Model = BackBone.Model.extend({
...
sync: function(method, model, options) {
//Use AJAX to call StackMob's REST API
//Save/Fetch Data
//Authenticate users
//etc...
}
...
});
</code></pre>
</section>
-->
<section>
<h2>Initialize</h2>
<pre><code class="brush: javascript;">
StackMob.init({
appName: 'html5devconf',
clientSubdomain: 'stackmob',
apiVersion: 0
});
</code></pre>
</section>
<section>
<section>
<h2>Server-Side Persistence: Create</h2>
Syntax:
<pre><code class="brush: javascript;">
var td = new Todo({
action: 'Prepare for SFJS',
priority: 'high'
});
td.create(); //AJAX call to StackMob REST API
</code></pre>
</section>
<section>
<h2>Let's Try It!</h2>
<p>var todo = new Todo(</p>
<textarea id="createtodo">
{
"action": "Test out the demo",
"priority": "high",
"done": false,
"reminders":
["monday","tuesday", "wednesday"]
}
</textarea>
<p>);</p>
<p>todo.create();</p>
<p><input id="create" type="button" class="button" value="Create"/></p>
<script type="text/javascript">
$(document).ready(function() {
$('#create').click(function() {
var json = $('#createtodo').val().trim();
var todo = new Todo(JSON.parse(json));
todo.create(SMDebug.callbacks('Creating TODO', {
target: 'createtodo',
success: function(model) {
$('#readitem').val(model.get('todo_id'));
$('#updateitem').val(model.get('todo_id'));
$('#deleteitem').val(model.get('todo_id'));
}
}));
});
});
</script>
</section>
<section>
<h2>Let's check it out!</h2>
<p>Web Dashboard</p>
<p><a href="https://www.stackmob.com/platform/api/schemas/" target="_blank"><img width="500px" src="https://s3.amazonaws.com/static.stackmob.com/images/screenshots/overview/StackMob_Manage_Schemas.png" alt="StackMob: Object Browser"/></a></p>
</section>
<section>
<h2>Save to "todo" table</h2>
Syntax:
<pre><code class="brush: javascript; highlight: [3,13]">
//Declare once per page
var Todo = StackMob.Model.extend({
schemaName: 'todo'
});
...
var td = new Todo({
action: 'Prepare for SFJS',
priority: 'high'
});
td.create();
</code></pre>
</section>
<section>
<h2>Asynchronous: Callbacks</h2>
<pre><code class="brush: javascript;">
td.create({
success: function(model) {
console.debug(model.toJSON());
},
error: function(model, response) {
console.debug('whoops');
}
});
</code></pre>
</section>
</section>
<section>
<section>
<h2>Read from DB</h2>
<a href="javascript:void(0);">Read Item</a>
<pre><code class="brush: javascript;">
var todo = new Todo({ todo_id: '1234' });
todo.fetch(callbacks);
</code></pre>
</section>
<section>
<h2>Try Read by ID</h2>
<p>var todo = new Todo({ todo_id: <input id="readitem" type="text" value=""/> });</p>
<p>todo.fetch();</p>
<p>
<textarea id="readtodo"></textarea>
</p>
<p><input id="read" type="button" class="button" value="Read Item"/></p>
<script type="text/javascript">
$(document).ready(function() {
$('#read').click(function() {
var id = $('#readitem').val().trim();
var todo = new Todo({ todo_id: id });
todo.fetch(SMDebug.callbacks('Reading TODO', 'readtodo'));
});
});
</script>
</section>
</section>
<section>
<section>
<h2>Update DB</h2>
<a href="javascript:void(0);">Update Item</a>
<pre><code class="brush: javascript;">
var todo = new Todo({ todo_id: '1234' });
todo.save({ somethingnew: 'hi'}, callbacks);
</code></pre>
</section>
<section>
<h2>Try Updating!</h2>
<p>var todo = new Todo({ todo_id: <input id="updateitem" type="text" value=""/> });</p>
<p>todo.save(</p>
<p>
<textarea id="updatetodo">
{
"action": "updating done to true",
"done": true
}
</textarea>
</p>
<p>);</p>
<p><input id="update" type="button" class="button" value="Update Item"/></p>
<script type="text/javascript">
$(document).ready(function() {
$('#update').click(function() {
var id = $('#updateitem').val().trim();
var todo = new Todo({ todo_id: id });
var json = JSON.parse($('#updatetodo').val().trim());
todo.save(json, SMDebug.callbacks('Update TODO', 'updatetodo'));
});
});
</script>
</section>
</section>
<section>
<section>
<h2>Delete from DB</h2>
<a href="javascript:void(0);">Delete Item</a>
<pre><code class="brush: javascript;">
var todo = new Todo({ todo_id: '1234' });
todo.destroy(callbacks);
</code></pre>
</section>
<section>
<h2>Try Deleting!</h2>
<p>var todo = new Todo({ todo_id: <input id="deleteitem" type="text" value=""/> });</p>
<p>todo.destroy();</p>
<p><input id="delete" type="button" class="button" value="Delete Item"/></p>
<textarea id="deletetodo"></textarea>
<script type="text/javascript">
$(document).ready(function() {
$('#delete').click(function() {
var id = $('#deleteitem').val().trim();
var todo = new Todo({ todo_id: id });
todo.destroy(SMDebug.callbacks('Delete TODO', {
target: 'deletetodo',
success: function(result) {
$('#deletetodo').val('Item ' + id + ' deleted!');
}
}));
});
});
</script>
</section>
</section>
<section>
<section>
<h2>Collections</h2>
<pre><code class="brush: javascript">
//From earlier..
var Todo = StackMob.Model.extend({
schemaName: 'todo'
});
...
//Same as Backbone..
var Todos = StackMob.Collection.extend({
model: Todo
});
var todos = new Todos();
todos.fetch();
</code></pre>
</section>
<section>
<h2>Fetch your Todos!</h2>
<p>var todos = new Todos();</p>
<p>todos.fetch();</p>
<p><input id="fetchcollection" type="button" class="button" value="Fetch your Todos"/></p>
<textarea id="fetchtodos"></textarea>
<script type="text/javascript">
$(document).ready(function() {
$('#fetchcollection').click(function() {
var todos = new Todos();
todos.fetch(SMDebug.callbacks('Fetch Todos', 'fetchtodos'));
});
});
</script>
</section>
</section>
<section>
<section>
<h2>Queries: Fetching specific models</h2>
<p>Getting Finished Todos</p>
<pre><code class="brush: javascript;">
var q = new StackMob.Collection.Query();
q.equals('done', true);
var todos = new Todos();
todos.query(q, callbacks);
</code></pre>
</section>
<section>
<h2>Get Finished Todos</h2>
<pre><code class="brush: javascript;">
var q = new StackMob.Collection.Query();
q.equals('done', true);
var todos = new Todos();
todos.query(q, callbacks);
</code></pre>
<p><input type="button" class="button" id="querycollection" value="Get Finished Todos"/></p>
<textarea id="fetchfinishedtodos"></textarea>
<script type="text/javascript">
$(document).ready(function() {
$('#querycollection').click(function() {
var q = new StackMob.Collection.Query();
q.equals('done', true);
var todos = new Todos();
todos.query(q, SMDebug.callbacks('Query Finished Todos', 'fetchfinishedtodos'));
});
});
</script>
</section>
<section>
<h2>Filter Queries</h2>
<pre><code class="brush: javascript;">
var q = new StackMob.Collection.Query();
q.lt('age', 21); //less than
q.gt('followers', 30); //greater than
q.notEquals('age', 5); //not equals
var people = new People(); //StackMob.Collection
people.query(q, callbacks);
</code></pre>
</section>
<section>
<h2>And more...</h2>
<pre><code class="brush: javascript;">
var q = new StackMob.Collection.Query();
q.orderAsc('age'); //order by ascending
q.setRange(0,4); //pagination first 5 results
//select certain fields
q.select('username').select('age').select('followers');
var people = new People(); //StackMob.Collection
people.query(q, callbacks);
</code></pre>
</section>
</section>
<section>
<section>
<h2>Relationships</h2>
<p>Related Objects</p>
<p>User has many Todos</p>
</section>
<section>
<h2>Relationship: User → Todos</h2>
<ul>
<li><a href="https://www.stackmob.com/platform/api/schemas/edit/user" target="blank">Edit User Schema</a></li>
<li>Add one-to-many "todos" relationship</li>
</ul>
</section>
<section>
<h2>Give Todo Items to User</h2>
<pre><code class="brush: javascript;">
var todo1 = new Todo({ action: 'take out the trash' });
var todo2 = new Todo({ action: 'do the laundry' });
var todo3 = new Todo({ action: 'prepare my slides!' });
var user = new StackMob.User({ username: 'ericktai' });
user.addRelationship('todos', [todo1, todo2, todo3], callbacks);
</code></pre>
</section>
<section>
<h2>Let's try it. But first..</h2>
<p>Let's see what "ericktai" looks like:</p>
<textarea id="readuser"></textarea>
<p><input type="button" id="fetchuser" class="button" value="Fetch User"/></p>
<script type="text/javascript">
$(document).ready(function() {
$('#fetchuser').click(function() {
var user = new StackMob.User({ username: 'ericktai' });
user.fetch(SMDebug.callbacks('Fetch User', 'readuser'));
});
});
</script>
</section>
<section>
<h2>Add Todos to User</h2>
<textarea id="addtodos"></textarea>
<p><input type="button" id="addtodoitems" class="button" value="Add Todos to User"/></p>
<script type="text/javascript">
$(document).ready(function() {
$('#addtodoitems').click(function() {
var todo1 = new Todo({ action: 'take out the trash' });
var todo2 = new Todo({ action: 'do the laundry' });
var todo3 = new Todo({ action: 'prepare my slides!' });
var user = new StackMob.User({ username: 'ericktai' });
user.addRelationship('todos', [todo1, todo2, todo3], SMDebug.callbacks('Add Todos to User', 'addtodos'));
});
});
</script>
</section>
<section>
<h2>Expand: Get Full Related Objects</h2>
<pre><code class="brush: javascript;">
//Use StackMob.Model#fetchExpanded
var user = new StackMob.User({ username: 'ericktai' });
user.fetchExpanded(1, callbacks);
</code></pre>
<textarea id="readuserexpanded"></textarea>
<p><input type="button" id="fetchuserexpanded" class="button" value="Fetch Expanded User"/></p>
<script type="text/javascript">
$(document).ready(function() {
$('#fetchuserexpanded').click(function() {
var user = new StackMob.User({ username: 'ericktai' });
user.fetchExpanded(1, SMDebug.callbacks('Fetch Expanded User', 'readuserexpanded'));
});
});
</script>
</section>
</section>
<section>
<section>
<h2>User Authentication</h2>
<pre><code class="brush: javascript;">
//User created via user.create()
var user = new StackMob.User({
username: 'chucknorris',
password: 'myfists'
});
user.login(callbacks);
...
StackMob.isUserLoggedIn('chucknorris'); //returns true;
user.isLoggedIn(); //returns true;
</code></pre>
</section>
<section>
<h2>Security → OAuth 2.0</h2>
<ul>
<li>Industry Standard: OAuth 1.0/2.0</li>
<li>Public/Private Keys identify your app's requests</li>
<li>FB/Twitter: OAuth 2.0. Username/Password</li>
<li>In current JS SDK for pre-trials</li>
</ul>
</section>
<section>
<h2>Access Controls</h2>
<ul>
<li>Share objects to certain users</li>
<li>Limit visibility</li>
<li>Coming very very soon</li>
</ul>
</section>
</section>
<section>
<section>
<h2>Even more flexibility: Custom Code</h2>
<ul>
<li>Java/Scala Server Side SDK</li>
<li>Write Code - StackMob REST-ifies it</li>
<li>JS can execute server code via REST API!</li>
<li>JS receives your custom JSON response too</li>
</ul>
<p style="margin-top: 30px;">Or include us in NodeJS</p>
</section>
<section>
<h2>Call Custom Code from JS!</h2>
<pre><code class="brush: javascript;">
StackMob.customcode('helloworld', {
success: function(result) {
console.debug(result.toJSON())
// Prints { msg: 'Hello World!' }
},
error: function(result) {}
});
</code></pre>
</section>
<section>
<h2>Custom Code Example</h2>
<pre><code class="brush: java">
//Java
public class HelloWorldExample implements
CustomCodeMethod {
@Override
public String getMethodName() {
return "hello_world";
}
@Override
public ResponseToProcess execute(...) {
//Do fancy server side things
Map<String, String> json =
new HashMap<String, String>();
json.put("msg", "hello world!");
return new ResponseToProcess(..., json);
}
}
</code></pre>
</section>
<section>
<h2>Defines your REST endpoint</h2>
<p><code>http://api.mob1.stackmob.com/hello_world</code></p>
<pre><code class="brush: java; highlight: [7]">
//Java
public class HelloWorldExample implements
CustomCodeMethod {
@Override
public String getMethodName() {
return "hello_world";
}
...
}
</code></pre>
</section>
<section>
<h2>Defines your return JSON</h2>
<p><code>{ msg: "hello world!" }</code></p>
<pre><code class="brush: java; highlight: [12]">
//Java
public class HelloWorldExample implements
CustomCodeMethod {
...
@Override
public ResponseToProcess execute(...) {
//Do fancy server side things
Map<String, String> json =
new HashMap<String, String>();
json.put("msg", "hello world!");
return new ResponseToProcess(..., json);
}
}
</code></pre>
</section>
</section>
<section>
<h2>Hosting & Custom Domains</h2>
<ul>
<li>Not just development platform</li>
<li>Host too! Even use your own domain: CNAME</li>
<li>Hosting <a href="https://www.stackmob.com/platform/account/html/settings" target="_blank">Integrated with GitHub</a></li>
</ul>
</section>
<section>
<h2>Development & Production Environments</h2>
<ul>
<li>Different databases</li>
<li>Only deploy when you're ready!</li>
<li><a href="https://www.stackmob.com/platform/deploy/" target="_blank">Easy rollout/rollback</a></li>
</ul>
</section>
<section>
<h2>API Versions</h2>
<ul>
<li>Backwards support old clients (PhoneGap)</li>
<li>Concurrently run different versions of your custom code/schemas</li>
</ul>
</section>
<section>
<h2>Adding a backend with StackMob</h2>
<ul>
<li>Simple</li>
<li>Seamless</li>
<li>Flexible</li>
<li>Powerful</li>
<li>Free → Grow</li>
</ul>
</section>
<section>
<h2>Resources</h2>
<ul>
<li><a href="https://www.stackmob.com/signup" target="_blank">Get a Free Account</a></li>
<li><a href="http://www.stackmob.com/devcenter/docs/Javascript-SDK-API" target="_blank">StackMob JS SDK</a></li>
<li><a href="http://www.stackmob.com/devcenter/docs/JS-SDK-Tutorial" target="_blank">StackMob JS Tutorial</a></li>
<li><a href="http://www.stackmob.com/devcenter/docs/Datastore-API#|js" target="_blank">All SDK Docs</a></li>
</ul>
</section>
<section>
<h2>After Party!</h2>
<h3>541 8th st, SF, CA (8th and Bryant)</h3>
<ul>
<li>Free Food: Tacos</li>
<li>Free Drinks & Beer</li>
<li>Come meet us and just hang out!</li>
</ul>
<p><a href="http://html5devconf.com/parties.html" target="_blank">http://html5devconf.com/parties.html</a></p>
</section>
</div>
<!-- The navigational controls UI -->
<aside class="controls">
<a class="left" href="#">◄</a>
<a class="right" href="#">►</a>
<a class="up" href="#">▲</a>
<a class="down" href="#">▼</a>
</aside>
<!-- Displays presentation progress, max value changes via JS to reflect # of slides -->
<div class="progress"><span></span></div>
</div>
<script type="text/javascript" src="../reveal.js/js/reveal.js"></script>
<script type="text/javascript">
Reveal.initialize({
// Display controls in the bottom right corner
controls: true,
// Display a presentation progress bar
progress: true,
// If true; each slide will be pushed to the browser history
history: true,
// Loops the presentation, defaults to false
loop: false,
// Flags if mouse wheel navigation should be enabled
mouseWheel: false,
// UI style
theme: 'default', // default/neon
rollingLinks: false,
// Transition style
transition: 'default' // default/cube/page/concave/linear(2d)
});
</script>
</body>
</html>