Skip to content

Commit 0a98484

Browse files
committed
ember slides
1 parent 7368c8b commit 0a98484

File tree

1 file changed

+262
-2
lines changed

1 file changed

+262
-2
lines changed

index.html

+262-2
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@
280280
# TryItEndpointOption & TryItEndpointPathInput
281281

282282
### work in similar ways
283-
### once a an element is selected or the input field is active
284-
### the `onSubmit` or the `onSelected` callbacks are triggered
283+
### once an element is selected or the input field is submitted
284+
### the `onSelected` or the `onSubmit` callbacks are triggered
285285

286286
---
287287

@@ -368,6 +368,266 @@
368368
### callbacks are called by subcomponents and "bubbled" up
369369
### `setState` in `TryItComponent`
370370
### Rerender all the things (with VirtuaDOM)
371+
372+
---
373+
374+
# Ember can React!
375+
376+
## Components layout
377+
```html
378+
<script type="text/x-handlebars" data-template-name="components/try-it">
379+
<div class="control-bar">
380+
{{try-it-endpoint-selector
381+
selectedEndpoint=selectedEndpoint
382+
selected="didSelectEndpoint"}}
383+
384+
{{try-it-endpoint-path-form
385+
path=endpointPath
386+
updated="didUpdatePath"}}
387+
</div>
388+
389+
{{try-it-console json=json}}
390+
</script>
391+
```
392+
393+
---
394+
class: center, middle
395+
396+
# DONE
397+
398+
---
399+
class: center, middle
400+
401+
## Just kidding...
402+
---
403+
404+
# TryItComponent
405+
406+
## Holds all the state
407+
```javascript
408+
App.TryItComponent = Ember.Component.extend({
409+
classNames: 'try-it-component',
410+
selectedEndpoint: ENDPOINTS[0],
411+
endpointPath: ENDPOINTS[0].path,
412+
json: '{}',
413+
414+
actions: {
415+
didSelectEndpoint: function(endpoint) {
416+
this.set('selectedEndpoint', endpoint);
417+
this.set('endpointPath', endpoint.path);
418+
this.loadJSON(endpoint.path);
419+
},
420+
421+
didUpdatePath: function(path) {
422+
this.loadJSON(path);
423+
}
424+
},
425+
426+
loadJSON: function(path) { /*...*/ },
427+
428+
loadInitialJSON: function() { /*...*/ }.on('didInsertElement')
429+
});
430+
```
431+
432+
---
433+
434+
# TryItComponent
435+
436+
## Wiring it up
437+
438+
```html
439+
<script type="text/x-handlebars" data-template-name="components/try-it">
440+
<div class="control-bar">
441+
{{try-it-endpoint-selector
442+
selectedEndpoint=selectedEndpoint
443+
selected="didSelectEndpoint"}}
444+
445+
{{try-it-endpoint-path-form
446+
path=endpointPath
447+
updated="didUpdatePath"}}
448+
</div>
449+
450+
{{try-it-console json=json}}
451+
</script>
452+
```
453+
### uses bindings and passes action names instead of callbacks
454+
### for now :)
455+
456+
---
457+
458+
# TryItEndpointSelector
459+
460+
### Holds only open/close state
461+
462+
```javascript
463+
464+
App.TryItEndpointSelectorComponent = Ember.Component.extend({
465+
classNames: 'endpoint-selector',
466+
classNameBindings: 'isOpen:open',
467+
468+
actions: {
469+
showList: function() {
470+
this.set('isOpen', true);
471+
},
472+
473+
dismissList: function() {
474+
this.set('isOpen', false);
475+
},
476+
477+
didSelectEndpoint: function(endpoint) {
478+
this.sendAction('selected', endpoint);
479+
}
480+
}
481+
});
482+
```
483+
484+
---
485+
486+
# TryItEndpointSelector
487+
488+
```html
489+
<script type="text/x-handlebars"
490+
data-template-name="components/try-it-endpoint-selector">
491+
<div class="endpoint-selector-label" {{action "showList"}}>
492+
{{~selectedEndpoint.label~}}
493+
</div>
494+
495+
{{#if isOpen}}
496+
{{try-it-endpoint-selector-list
497+
selectedEndpoint=selectedEndpoint
498+
dismiss="dismissList"
499+
selected="didSelectEndpoint"}}
500+
{{/if}}
501+
</script>
502+
```
503+
504+
---
505+
506+
# TryItEndpointSelectorList
507+
508+
```javascript
509+
App.TryItEndpointSelectorListComponent = Ember.Component.extend({
510+
tagName: 'ol',
511+
classNames: 'endpoint-selector-list',
512+
endpoints: ENDPOINTS,
513+
514+
actions: {
515+
didSelectEndpoint: function(endpoint) {
516+
this.sendAction('selected', endpoint);
517+
}
518+
},
519+
520+
didInsertElement: function() {
521+
var view = this;
522+
523+
Ember.run.next(function() {
524+
Ember.$(document).one('click', function() {
525+
view.sendAction('dismiss');
526+
});
527+
});
528+
529+
}
530+
});
531+
```
532+
533+
---
534+
535+
# TryItEndpointSelectorList
536+
537+
```html
538+
<script type="text/x-handlebars"
539+
data-template-name="components/try-it-endpoint-selector-list">
540+
{{#each endpoint in endpoints}}
541+
{{#try-it-endpoint-selector-list-item
542+
endpoint=endpoint
543+
selectedEndpoint=selectedEndpoint
544+
selected="didSelectEndpoint"}}
545+
{{endpoint.label}}
546+
{{/try-it-endpoint-selector-list-item}}
547+
{{/each}}
548+
</script>
549+
```
550+
---
551+
552+
# TryItEndpointSelectorListItem & TryItEndpointPathForm
553+
554+
### work in similar ways
555+
### once an element is selected or the input field is submitted
556+
### the `selected` or the `updated` actions are triggered
557+
558+
---
559+
560+
# TryItComponent
561+
```javascript
562+
App.TryItComponent = Ember.Component.extend({
563+
/*...*/
564+
actions: {
565+
didSelectEndpoint: function(endpoint) {
566+
this.set('selectedEndpoint', endpoint);
567+
this.set('endpointPath', endpoint.path);
568+
this.loadJSON(endpoint.path);
569+
},
570+
didUpdatePath: function(path) {
571+
this.loadJSON(path);
572+
}
573+
},
574+
loadJSON: function(path) {
575+
var view = this;
576+
577+
$.ajax({
578+
url: 'http://lcboapi.com/' + path,
579+
dataType: 'jsonp'
580+
}).then(function(data) {
581+
view.set('json', JSON.stringify(data, null, 2));
582+
});
583+
},
584+
/*...*/
585+
});
586+
```
587+
588+
---
589+
590+
# TryItConsole
591+
592+
## receives the current json as a `binding`
593+
```html
594+
<script type="text/x-handlebars" data-template-name="components/try-it">
595+
...
596+
{{try-it-console json=json}}
597+
...
598+
</script>
599+
```
600+
601+
---
602+
603+
# TryItConsole
604+
605+
## receives the current json as a `binding`
606+
```javascript
607+
App.TryItConsoleComponent = Ember.Component.extend({
608+
classNames: 'console',
609+
610+
highlightedJSON: function() {
611+
return Prism.highlight(this.get('json'), Prism.languages.json);
612+
}.property('json'),
613+
614+
didUpdateConsole: function() {
615+
this.$().scrollTop(0);
616+
}.observes('highlightedJSON').on('didInsertElement')
617+
});
618+
```
619+
620+
---
621+
622+
# How to Ember
623+
624+
### state lives in `TryItComponent`
625+
### subcomponents get the state as `bindings` (that we use one way)
626+
### subcomponents pass down action names
627+
### actions are sent by subcomponents and "bubbled" up
628+
### `set` in `TryItComponent`
629+
### Rerender what's needed
630+
371631
</textarea>
372632
<script src="remark.js">
373633
</script>

0 commit comments

Comments
 (0)