Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
choo-lazy-view
Advanced tools
Lazily load views as the router invokes them. Built for split-require but should work with any software with a similar callback signature.
var splitRequire = require('split-require')
var LazyView = require('choo-lazy-view')
var html = require('choo/html')
var choo = require('choo')
var app = choo()
app.route('/', main)
app.route('/a', LazyView.create((callback) => splitRequire('./a', callback)))
app.route('/b', LazyView.create((callback) => splitRequire('./b', callback)))
module.exports = LazyView.mount(app, 'body')
function main () {
return html`
<body class="Home">
<h1>home</h1>
<a href="/a">a</a><br>
<a href="/b">b</a>
</body>
`
}
The module exposes a Nanocomponent class with two static methods which are used for wrapping your views and choo.mount
.
LazyView.create(callback, loader?)
Accepts a callback and an optional loader view. The callback will be invoked when the returned function is called upon (called immediately in node). The callback, in turn, should load the required view and relay it's response (or error) back to the caller.
app.route('/page', LazyView.create(function (callback) {
fetchViewSomehow(callback)
}))
The second argument is optional and should be a function or a DOM node which will be displayed while loading. By default, the node used to mount the application in the DOM is used as loader (meaning the view remains unchanged while loading).
app.route('/a', LazyView.create(
(callback) => splitRequire('./a', callback),
(state, emit) => html`<h1>Loading view…</h1>`
))
LazyView.mount(app, selector)
Wrapper function for app.mount
. Returns a promise which resolves once the application is ready. Needed because split-require resolves modules asynchronously
// server.js
Promise.resolve(require('./index')).then(function (app) {
var html = app.toString('/a')
})
You may extend on LazyView to add a shared framework wrapper, e.g. a header, footer, etc.
// components/view/index.js
var html = require('choo/html')
var LazyView = require('choo-lazy-view')
var Header = require('../header')
var Footer = require('../footer')
module.exports = class View extends LazyView {
createElement (state, emit) {
return html`
<body>
${state.cache(Header, 'header')}
${super.createElement(state, emit)}
${state.cache(Footer, 'footer')}
</body>
`
}
}
// index.js
var choo = require('choo')
var splitRequire = require('split-require')
var View = require('./components/view')
var app = choo()
app.route('/', View.create((callback) => splitRequire('./views/home', callback)))
module.exports = View.mount(app, 'body')
Events are namespaced under choo-lazy-view
and emitted when loading views.
choo-lazy-view:fetch
When fetching a view.
choo-lazy-view:done
When the view has been fetched and is about to rerender.
FAQs
Lazily fetch view when needed
The npm package choo-lazy-view receives a total of 17 weekly downloads. As such, choo-lazy-view popularity was classified as not popular.
We found that choo-lazy-view demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.