Skip to content

Commit ce76b73

Browse files
committed
Update
1 parent 60a1d75 commit ce76b73

File tree

5 files changed

+262
-0
lines changed

5 files changed

+262
-0
lines changed

deku.md

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
title: Deku
3+
category: JavaScript libraries
4+
---
5+
6+
```js
7+
/** @jsx element */
8+
import element from 'virtual-element' // replacement for React.createElement
9+
import {render, tree} from 'deku'
10+
11+
var app = <div class='my-app'>Hello World!</div>
12+
13+
render(tree(app), document.body)
14+
```
15+
16+
## Components
17+
18+
```js
19+
Button = {
20+
render () { return <button>Submit</button> }
21+
}
22+
23+
App = {
24+
render () { return <div><Button /></div> }
25+
}
26+
27+
render(tree(<App />), document.body)
28+
// or with virtual-element
29+
render(tree(element(App)), document.body)
30+
```
31+
32+
## Component props/state
33+
34+
```js
35+
App = {
36+
render ({ props, state }) {
37+
return <div>{ /*...use state.store here*/ }</div>
38+
}
39+
40+
initialState (props) {
41+
return { store: store.getState() }
42+
},
43+
44+
afterMount (comp, el, setState) {
45+
store.subscribe(() => setState({ store: store.getState() }))
46+
}
47+
}
48+
49+
render(tree(<App />), document.body)
50+
```
51+
52+
## Events
53+
54+
```js
55+
<a onClick={onClick}>{props.text}</a>
56+
```
57+
58+
## Magic virtual element
59+
Use [magic-virtual-element](https://github.com/dekujs/magic-virtual-element) to enable nice classnames.
60+
61+
```
62+
import element from 'magic-virtual-element'
63+
<div style={style} class={[ 'button', '-active' ]}>
64+
```
65+
66+
## Reference
67+
68+
```
69+
name = 'MyComponent'
70+
71+
// Defaults
72+
initialState (props) {...} // return initial state
73+
defaultProps = { style: 'rout' }
74+
75+
// Render
76+
render ({props, state}, setState) {...}
77+
78+
// Lifecycle
79+
beforeUpdate ({props, state, id}, nextProps, nextState) {}
80+
afterRender ({props, state, id}, el) {}
81+
afterUpdate ({props, state, id}, prevProps, prevState, setState) {}
82+
afterMount ({props, state, id}, el, setState) {}
83+
beforeUnmount ({props, state, id}, el) {}
84+
```
85+
86+
See: <https://www.npmjs.com/package/deku>

meow.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: Meow
3+
category: JavaScript libraries
4+
---
5+
6+
```js
7+
const cli = require('meow')(`
8+
Usage: appname [options]
9+
10+
Options:
11+
-h, --help show usage information
12+
-v, --version print version info and exit
13+
`, {
14+
alias: {
15+
alias: { h: 'help', v: 'version', x: 'excludeTag' },
16+
string: ['lang'],
17+
boolean: ['pager'],
18+
default: { lang: 'en' },
19+
'--': true,
20+
stopEarly: true, /* populate _ with first non-option */
21+
unknown: function () { ... } /* invoked on unknown param */
22+
})
23+
24+
cli.flags // { excludeTag: true }
25+
cli.input // []
26+
27+
// yes, flags are camelCased
28+
```
29+
30+
Also see [minimist](minimist.html).

mongodb.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: MongoDB
3+
category: Development
4+
---
5+
6+
## Querying
7+
8+
```
9+
{ name: 'john' }
10+
{ name: { $eq: 'john' } }

virtual-dom.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: Virtual-dom
3+
category: JavaScript libraries
4+
---
5+
6+
See <https://www.npmjs.com/package/virtual-dom>
7+
8+
```js
9+
var h = require('virtual-dom/h')
10+
var diff = require('virtual-dom/diff')
11+
var patch = require('virtual-dom/patch')
12+
var createElement = require('virtual-dom/create-element')
13+
```
14+
15+
### Rendering
16+
17+
```js
18+
tree = h('div', { style: { color: 'blue' } }, [ 'hello' ])
19+
el = createElement(tree)
20+
document.body.appendChild(root)
21+
```
22+
23+
### Updating
24+
25+
```js
26+
tree2 = h('div', { style: { color: 'blue' } }, [ 'hello world' ])
27+
delta = diff(tree, tree2)
28+
el = patch(el, delta) // patch() modifies el
29+
```

vue.md

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
title: Vue
3+
category: JavaScript libraries
4+
---
5+
6+
### Lists
7+
8+
```html
9+
<li v-for="todo in todos">
10+
{{ todo.text }}
11+
{{ $index }}
12+
</li>
13+
```
14+
15+
### Events
16+
17+
```html
18+
<button v-on:click='submit'>Go</button>
19+
```
20+
21+
### Components
22+
23+
```js
24+
new Vue({
25+
components: { app: App }
26+
})
27+
```
28+
29+
## API
30+
31+
```js
32+
Vue.extend({ ... }) // creating components
33+
Vue.nextTick(() => {...})
34+
35+
Vue.set(object, key, val) // reactive
36+
Vue.delete(object, key)
37+
38+
Vue.directive('my-dir', { bind, update, unbind })
39+
// <div v-my-dir='...'></div>
40+
41+
Vue.elementDirective('my-dir', { bind, update, unbind })
42+
// <my-dir>...</my-dir>
43+
44+
Vue.component('my-component', Vue.extend({ .. }))
45+
46+
Vue.partial('my-partial', '<div>hi {{msg}}</div>')
47+
// <partial name='my-partial'></partial>
48+
```
49+
50+
```js
51+
new Vue({
52+
data: { ... }
53+
props: ['size'],
54+
props: { size: Number },
55+
computed: { fullname() { return this.name + ' ' + this.lastName } },
56+
methods: { go() { ... } },
57+
watch: { a (val, oldVal) { ... } },
58+
el: '#foo',
59+
template: '...',
60+
replace: true, // replace element (default true)
61+
62+
// lifecycle
63+
created () {},
64+
beforeCompile () {},
65+
compiled () {},
66+
ready () {}, // $el is inserted for the first time
67+
attached () {},
68+
detached () {},
69+
beforeDestroy () {},
70+
destroyed () {},
71+
72+
// options
73+
directives: {},
74+
elementDirectives: {},
75+
filters: {},
76+
components: {},
77+
transitions: {},
78+
partials: {}
79+
})
80+
```
81+
82+
## Vue templates
83+
Via [vueify](https://www.npmjs.com/package/vueify)
84+
85+
```js
86+
// app.vue
87+
<template>
88+
<h1 class="red">{{msg}}</h1>
89+
</template>
90+
91+
<script>
92+
module.exports = {
93+
data () {
94+
return {
95+
msg: 'Hello world!'
96+
}
97+
}
98+
}
99+
</script>
100+
```
101+
102+
Also
103+
104+
```html
105+
<template lang='jade'>
106+
h1(class='red') {{msg}}
107+
</template>

0 commit comments

Comments
 (0)