(What I've learnt after writing 290 modules)
meta-test asynct synct
testbed test-report-test test-child
test-runner test-cmd it-is
assertions asynct_tests macgyver
event-stream JSONStream through
fsm-stream map-stream rpc-stream
git-stream message-stream push-stream
header-stream msgpack-stream recurse-stream
sort-stream regular-stream relational-join-stream
pause-stream tab-stream repl-stream
duplex stream-combiner redis-protocol-stream
mux-demux stream-serializer stream-to-pull-stream
reconnect stream-spec pull-stream-to-stream
stream-tester post-message-stream
input.pipe(transform).pipe(output)
snob crdt scuttlebutt
scuttlebucket r-edit level-scuttlebutt
r-value scuttlebutt-remote localstorage-scuttlebutt
repred schema-scuttlebutt r-array
stream.pipe(replicator.createStream).pipe(stream)
replicator.set('foo', 'bar')
var bar = replicator.get('foo')
replicator.on('change', function (key, value) {
console.log('change', key, value)
})
strm
pull-stream pull-glob pull-sorted-merge
pull-through reg-spec pull-traverse
pull-cat pull-http pull-split
pull-core pull-level pull-async-batch
pull-window pull-zip regular-stream
pull-crypto pull-markable pull-stream-range
pull-decode pull-merge pull-stream-to-stream
pull-flow pull-paramap pull-switch
pull-fs pull-pushable pull-tee
function values (array) {
var i = 0
return function (abort, cb) {
if(i > array.length) cb(true)
else cb(null, array[i++])
})
}
function sink (read) {
read(null, function next (end, data) {
if(!end) {
console.log(data)
read(null, next)
}
})
//pass the source to the sink
sink(values([1, 2, 3]))
//OR
var pull = require('pull-stream')
pull(values([1, 2, 3]), sink)
level-sublevel level-queue level-live-stream
level-manifest level-replicate level-test
level-trigger level-scuttlebutt level-update
level-couch-sync level-repred level-master
level-fix-range level-merkle level-view-stream
level-heavy level-merkle-tree level-search
level-window level-hooks level-in-flight
level-peek level-static level-index
level-post level-store level-inverted-index
powerful yet simple key-value api.
put, get, del, batch, createReadStream
(architecture is optimized for in order reads, and it's great for real time data)
Some aspects of that...
We need to agree on some things, and modules can help us find agreement...
By Limiting the scope of that agreement
Since a module is small, it is achievable victory.
Each module has an emotional reward.
Becareful: publishing modules can be addictive.
when A published module that B uses, and B published module that A uses.
Modules make it easier to collaborate in a loose way, because we can use the same modules for different things.
We can collabotate, even though we have different goals.
Modules are like a building ladder, they make doing a hard thing into an easy thing.
Only particular things become good modules.
You must learn to detect the potential modules within your application.
but what problems make for good modules?
Hard Problems, vs. Messy Problems
Abstractions, vs. Layer of Indirection.
天 vs. 土
If making something a little cruder is easier, do it.
The easiest way to put your module closer to heaven is to make less of it.
var o = require('observable')
var v = o()
v(10) // set value
console.log(v()) // get value
v(console.log) // track value
v(12) // trigger change
function value () {
var _val, change
return function (val) {
return (
'undefined' === typeof val ? _val
: 'function' !== typeof val ? change && change(_val = val)
: ((change = val), val(_val), function () {
if(change === val) change = null
})
)}}
if you are using OSX or LINUX you are using UNIX
unix is mainly compromised of small utilities that input and output text.
the 核心 (provides the raw power)
the 壳 (allows that power to be easily directed)
the 模块 are programs that input and output text.
the 核心 is require('http')
the 壳 is connect/express
the 模块 are functions that alter or handle http request/response
the 核心 is IO
the 壳 is source.pipe(dest)
the 模块 are streams
the 核心 is LevelDown
the 壳 is levelup & level-sublevel
the 模块 are javascript that adds database features.
the 核心 is libuv * core modules
the 壳 is npm/require()
the 模块 are javascript functions that export one or more functions.
These don't really exist yet, but they could.
dagre - graph layout
graphlib-dot - parse dot files
dagre-d3 - render with d3
graphlib-git - generate graph of git commits
graphlib-adjacency
- graph from adjacency list
Lots of potential graph algorithms.
Steal ideas from matlab, or panda (python)
Table#get(row, col)
Table#set(row, col, value)
Table#addRow (afterRow, values)
Table#select(startRow, EndRow) //returns a view on this table.
https://github.com/maxogden/dat/issues/16
Basically, everything you'd need to implement a spreadsheet.
use Vec2 to bring Geometry to the DOM.
var v = new Vec2().set(x, y)
//many methods working with vectors.
get the dimensions of an element, natively...
function positon(element) {
var rect = element.getBoundingClientRect()
//if this object has margins, add them to the calculation.
//otherwise your numbers will be wrong!
var style = getComputedStyle(element)
return {
x: rec.left + parseFloat(style['margin-left']),
y: rec.top + parseFloat(style['margin-top'])
}
}
Suppose, you wanted to set the position, to an exact pixel?
(remember, position: absolute
means absolute position within parent)
function subtract(a, b) {
return { x: a.x - b.x, y: a.y - b.y }
}
function place (element, x, y) {
var pos = position(foo)
var parentPos = position(foo.parentElement)
var _pos = subtract(parentPos, pos)
foo.style.left = (x - _pos.y) + 'px'
foo.style.top = (y - _pos.y) + 'px'
}
TOO HARD!
var vdom = require('vec2-dom')
var r1 = vdom.element(e1)
var r2 = vdom.absolute(e2, true)
r2.set(r1.size.divide(2, true).subtract(r2.size.divide(2, true))
DRAG & DROP EXAMPLE
Window Manager as Front End Framework?
Window Manager!
maps
Thank you jing.js