Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
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({
mount: handleMount,
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...
A couple additional options are provided for defining render methods, alongside all the supported choo
options. While we refer to them as options, mount
and render
are required since byo has no render methods by default.
opts.mount
required | Mount the tree onto the root. Typically you will return the tree
or root
. Example:
function handleMount (tree, root) {
nanomount(root, tree)
return root
}
opts.render
required | Render the new tree. tree
, newTree
, and root
are available for morphing. Example:
function handleRender (tree, newTree, root) {
return nanomorph(tree, newTree)
}
opts.toString
Convert html (or vdom) to string. You'll usually define this method for server rendering. Example:
function handleToString (html) {
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
function handleMount (tree, root) {
rootNode = vdom.create(tree)
root.appendChild(rootNode)
return tree
})
function handleRender (tree, newTree, root) {
var patches = vdom.diff(tree, newTree)
rootNode = vdom.patch(rootNode, patches)
return newTree
})
var Inferno = require('inferno')
var hyperx = require('hyperx')
var html = hyperx(require('inferno-create-element'))
function handleMount (tree, root) {
return Inferno.render(tree, root)
})
function handleRender (tree, newTree, root) {
return Inferno.render(newTree, root)
})
var preact = require('preact')
var hyperx = require('hyperx')
var html = hyperx(preact.h)
function handleMount (tree, root) {
return preact.render(tree, root)
})
function handleRender (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)
function handleMount (tree, root) {
return ReactDOM.render(tree, root)
})
function handleRender (tree, newTree, root) {
return ReactDOM.render(newTree, root)
})
var html = require('snabby')
function handleMount (tree, root) {
html.update(root, tree)
return tree
})
function handleRender (tree, newTree, root) {
html.update(tree, newTree)
return newTree
})
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
The npm package byo receives a total of 0 weekly downloads. As such, byo popularity was classified as not popular.
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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.