Skip to content

Commit 32b4d00

Browse files
committed
Learn to yo-yo
1 parent 92905fb commit 32b4d00

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

learn-to-yo-yo/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Learn to yo-yo
2+
3+
> [https://youtu.be/MKJHuub6UJI](https://youtu.be/MKJHuub6UJI)
4+
5+
* Install [Node.js](https://nodejs.org/).
6+
* Install dependencies: `npm install`
7+
* Then run `npm start` and go to http://localhost:9966 in the browser.

learn-to-yo-yo/index.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var yo = require('yo-yo')
2+
var css = require('dom-css')
3+
4+
// var element = yo`<div>Grrrr</div>`
5+
// document.body.appendChild(element)
6+
//
7+
// setTimeout(function () {
8+
// yo.update(element, yo`<h1>Growl</h1>`)
9+
// }, 1000)
10+
11+
function list (items, onadd) {
12+
return yo`<ul>
13+
${items.map(function (item) {
14+
return yo`<li>${item}</li>`
15+
})}
16+
<li>${button(onadd)}</li>
17+
</ul>`
18+
}
19+
20+
function button (onclick) {
21+
var el = yo`<button onclick=${onclick}>add bear</button>`
22+
css(el, {
23+
'border-radius': 10
24+
})
25+
return el
26+
}
27+
28+
var bears = ['Polar', 'Brown', 'Grizzly']
29+
var element = list(bears, function onadd () {
30+
bears.push('Black')
31+
yo.update(element, list(bears, onadd))
32+
})
33+
document.body.appendChild(element)

learn-to-yo-yo/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "learn-to-yo-yo",
3+
"version": "0.1.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "budo index.js",
8+
"test": "node test.js"
9+
},
10+
"author": "Kyle Robinson Young <kyle@dontkry.com> (http://dontkry.com)",
11+
"license": "MIT",
12+
"devDependencies": {
13+
"budo": "^8.3.0"
14+
}
15+
}

0 commit comments

Comments
 (0)