Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
byo
or bring your own
is like choo without a renderer.
Clone of the choo example, but we bring bel, nanomount, and nanomorph ourselves.
var byo = require('byo')
var html = require('bel')
var nanomount = require('nanomount')
var nanomorph = require('nanomorph')
var app = byo()
app.define('mount', handleMount)
app.define('render', handleRender)
app.use(logger)
app.use(countStore)
app.route('/', mainView)
app.mount('body')
function handleMount (tree, root) {
nanomount(root, tree)
return root
}
function handleRender (tree, newTree, root) {
return nanomorph(tree, newTree)
}
function mainView (state, emit) {
return html`
<body>
<h1>count is ${state.count}</h1>
<button onclick=${onclick}>Increment</button>
</body>
`
function onclick () {
emit('increment', 1)
}
}
function logger (state, emitter) {
emitter.on('*', function (messageName, data) {
console.log('event', messageName, data)
})
}
function countStore (state, emitter) {
state.count = 0
emitter.on('increment', function (count) {
state.count += count
emitter.emit('render')
})
}
Under the hood, byo
is essentially a fork of choo
. At the moment, we'll keep byo
in API parity with choo
. Please refer to the choo documentation for details on routing, events, and the architecture in general. The only thing we need to document here is...
Because byo
has no render methods, we need to define them ourselves!
app.define(action, callback([params]))
Define a function to call on an action. Available actions are mount
, render
, and toString
. Each expects a function with slightly different parameters:
mount
*required
app.define('mount', function (tree, root) {
// mount tree onto root
// typically you will return tree/root
nanomount(root, tree)
return root
})
render
*required
app.define('render', function (tree, newTree, root) {
// render the new tree
// tree, newTree, and root are available for morphing
return nanomorph(tree, newTree)
})
toString
app.define('toString', function (html) {
// convert html (or vdom) to string
return html.toString()
})
If you like choo
use choo
, it's rad.
But sometimes bel
, nanomount
, or nanomorph
might not fit the needs of a project. Maybe you like virtual dom but you still want to build your apps choo
-style. byo
is the back-pocket tool for those scenarios. I'm maintaining this project because I currently have a need for nested components which we can't quite yet pull off with nanocomponent, so I opt for preact + hyperx.
Here are some examples of renderers with tagged template string implementations you can byo
:
var vdom = require('virtual-dom')
var hyperx = require('hyperx')
var html = hyperx(vdom.h)
var rootNode
app.define('mount', function (tree, root) {
rootNode = vdom.create(tree)
root.appendChild(rootNode)
return tree
})
app.define('render', function (tree, newTree, root) {
var patches = vdom.diff(tree, newTree)
rootNode = vdom.patch(rootNode, patches)
return newTree
})
var preact = require('preact')
var hyperx = require('hyperx')
var html = hyperx(preact.h)
app.define('mount', function (tree, root) {
return preact.render(tree, root)
})
app.define('render', function (tree, newTree, root) {
return preact.render(newTree, root, tree)
})
var React = require('react')
var ReactDOM = require('react-dom')
var hyperx = require('hyperx')
var html = hyperx(React.createElement)
app.define('mount', function (tree, root) {
return ReactDOM.render(tree, root)
})
app.define('render', function (tree, newTree, root) {
return ReactDOM.render(newTree, root)
})
var html = require('snabby')
app.define('mount', function (tree, root) {
html.update(root, tree)
return tree
})
app.define('render', function (tree, newTree, root) {
html.update(tree, newTree)
return newTree
})
var Inferno = require('inferno')
var hyperx = require('hyperx')
var html = hyperx(require('inferno-create-element'))
app.define('mount', function (tree, root) {
return Inferno.render(tree, root)
})
app.define('render', function (tree, newTree, root) {
return Inferno.render(newTree, root)
})
Thanks Yoshua Wuyts and the rest of the choo team (s/o dat) for the continual awsm work 🙏
FAQs
byo is like choo without a renderer
We found that byo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.