On Github wing9405 / slides
TechX 2015/03/04 @ Samsung SDS
나현익 (L4)
SDK 개발그룹, S-Core
var model = {};
Object.observe(model, function (changes) {
changes.forEach(function (c) {
alert('\n name: ' + c.name +
'\n type: ' + c.type +
'\n old value: ' + c.oldValue +
'\n cur value: ' + c.object[c.name]);
});
});Ex-1. Observing an object with Object.observe
var person= Ember.Object.create({
firstName: "Gildong",
lastName: "Hong",
fullName: function () {
return this.get("firstName") + this.get("lastName");
}.property("firstName", "lastName")
});
perseon.get("fullName"); // person.fullName
perseon.set("lastName", "Go"); // person.lastName = "Go"Ex-3. An object in Ember
<fs-node-dir> tech-day
<fs-node-dir> examples
<fs-node-file> ex1.html </fs-node-file>
<fs-node-file> ex2.html </fs-node-file>
</fs-node-dir>
<fs-node-dir git="repo"> slides
<fs-node-dir> .git </fs-node-dir>
<fs-node-dir git="unmodified"> css </fs-node-dir>
<fs-node-dir git="unmodified"> images
<fs-node-file git="unmodified"> dirty-checking.png </fs-node-file>
<fs-node-file git="unmodified"> dom-tree.png </fs-node-file>
<fs-node-file git="unmodified"> observe.png </fs-node-file>
</fs-node-dir>
<fs-node-dir git="unmodified"> js </fs-node-dir>
<fs-node-dir git="unmodified"> lib </fs-node-dir>
<fs-node-dir git="unmodified"> plugin </fs-node-dir>
<fs-node-dir git="unmodified"> text </fs-node-dir>
<fs-node-file git="unmodified"> .gitignore </fs-node-file>
<fs-node-file git="unmodified"> .travis.yml </fs-node-file>
<fs-node-file git="unmodified"> Gruntfile.js </fs-node-file>
...
</fs-node-dir>
</fs-node-dir>Ex-4. Only the semantic contents, without presentation details
var NameTag = document.registerElement('name-tag');
document.body.appendChild(new NameTag());Ex-5. Registering a new element name
document.registerElement('extended-button', {
prototype: Object.create(HTMLButtonElement.prototype)
});Ex-6. Extending another element
<div>
<label>Name: </label> <name-tag> </name-tag>
<script>
var proto = Object.create(HTMLElement.prototype);
proto.createdCallback = function () {
this.innerHTML = '<span> Gildong Hong </span>';
}
document.registerElement('name-taq', { prototype: proto });
</script>
</div>Ex-7. Filling the content of a custom element
<template id="mytemplate">
<img src="my-image.png" alt="my excelent image">
<div class="comment"></div>
</template>Ex-8. HTML template
var tmpl = document.querySelector('#mytemplate');
var clone = document.importNode(tmpl.content, true); // true: deep clone
document.body.appendChild(clone);Ex-9. Using template
<button>Hello, world!</button>
<script>
var host = document.querySelector('button');
var root = host.createShadowRoot();
root.textContent = '안녕, 세상아!';
</script>Ex-10. Hello world of Shadow DOM
<style>
.outer {
border: 2px solid brown;
border-radius: 1em;
background: red;
font-size: 20pt;
width: 12em;
height: 7em;
text-align: center;
}
.boilerplate {
color: white;
font-family: sans-serif;
padding: 0.5em;
}
.name {
color: black;
background: white;
font-family: "Marker Felt", cursive;
font-size: 45pt;
padding-top: 0.2em;
}
</style>
<div class="outer">
<div class="boilerplate">
Hi! My name is
</div>
<div class="name">
Bob
</div>
</div>Ex-11. Original code - Mixture of contents and presentation
<!-- true contents -->
<div id="nameTag">Bob</div>
<!-- presentation details -->
<template id="nameTagTemplate">
<style>
...
</style>
<div class="outer">
...
<div class="name">
Bob <!-- !!! -->
</div>
</div>
</template>Ex-10. Step 1: Extract true contents
<!-- true contents -->
<div id="nameTag">Bob</div>
<!-- presentation details -->
<template id="nameTagTemplate">
...
</template>
<script>
var shadow = document.querySelector('#nameTag').createShadowRoot();
var template = document.querySelector('#nameTagTemplate');
var clone = document.importNode(template.content, true);
shadow.appendChild(clone);
</script>Ex-13. Step 2: Populate the presentation layer using Shadow DOM
<template id="nameTagTemplate">
<style>
...
</style>
<div class="outer">
...
<div class="name">
<content></content> <!-- !!! -->
</div>
</div>
</template>Ex-14. Step 3: Using <content> to complete the separation
<template id="nameTagTemplate">
… same as Ex-14 …
</template>
<script>
var proto = Object.create(HTMLElement.prototype);
proto.createdCallback = function () {
var shadow = this.createShadowRoot();
var template = document.querySelector('#nameTagTemplate');
var clone = document.importNode(template.content, true);
shadow.appendChild(clone);
};
document.registerElement('name-tag', { prototype: poroto });
</script>Ex-15. Defining <name-tag> with Custom Element, HTML Template and Shadow DOM
<link rel="import" href="name-tag.html"> ... <name-tag> Bob </name-tag> <name-tag> Mary </name-tag> <name-tag> 홍길동 </name-tag>Ex-16. Importing the definition of <name-tag> in another file
{
"name": "My App",
"description": "My elevator pitch goes here",
"launch_path": "/index.html",
"icons": {
"512": "/img/icon-512.png",
"128": "/img/icon-128.png"
},
"developer": {
"name": "My Name",
"url": "http://my-homepage.org"
},
"default_locale": "en"
}Ex-17. manifest.json (an example)
... <link rel="manifest" href="manifest.json"> ...Ex-18. index.html
<picture> <source media="(min-width: 650px)" srcset="images/kitten-stretching.png"> <source media="(min-width: 465px)" srcset="images/kitten-sitting.png"> <img src="images/kitten-curled.png" alt="a cute kitten"> </picture>Ex-19. <picture> element in the above example