npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mnla

v0.0.4

Published

Dead simple universal JavaScript.

Downloads

5

Readme

MNLA

MNLA is a wrapper for the Manila template engine that provides universal (isomorphic) rendering and client-side data binding. It adds only 2.5KB of client-side code and 2KB of server-side code on top of the Manila template engine, which is 4KB of server-side code.

Installation

npm install mnla --save

This documentation assumes you are using Express.

Example Setup

You can demo the Hello World yourself:

git clone https://github.com/mgrahamjo/mnla && cd mnla/hello-world && npm install && node index

Server side:

// index.js
const express = require('express'),
    app = express(),
    mnla = require('mnla')();

app
    // Define the location of your static assets:
    .use(express.static('assets'))
    // If you aren't using a bundler like Browserify,
    // add a static route for the MNLA source code:
    .use(express.static('node_modules/mnla'))
    // Tell Express to use the MNLA template engine:
    .engine('mnla', mnla)
    .set('view engine', 'mnla')
    // Set up some routes:
    .get('/', require('./controllers/index'))
    .get('/message', require('./controllers/message')) // JSON endpoint
    // Start the app
    .listen(1337, () => {
        console.log('Listening on localhost:1337');
    });
// controllers/message.js
// Here is a controller for the json endpoint /message. 
module.exports = (req, res) => {
    res.json({
        message: "hello, world!"
    });
};
// controllers/index.js
const manila = require('mnla/server');

module.exports = (req, res) => {
    manila({
        // Here we define our component names and underlying data sources:
        // You can pass a json endpoint as a data source:
        message: require('./message'),
        // Or you can pass raw data:
        input: {
            message: "hello, world!"
        },
        // If you wanted to set up a client-side component
        // that isn't rendered on the server side, you would pass null
        // clientComponent: null
    },
    // Don't forget to pass req and res (the 'message' controller we included expects them)
    req, res)
    .then(templateData => {
        res.render('index', templateData);
    });
};
<!-- views/message.mnla -->
<!-- This is the template for the message component -->
<h1><:message:></h1>
<!-- views/input.mnla -->
<!-- This is the template for the input component -->
<!-- 'on' is a special method that you can use to listen to DOM events. -->
<!-- 'updateMessage' is a custom handler that we'll define in a client side script. -->
<input type="text" <:on('input', updateMessage):> value="<:message:>" />
<!-- views/index.mnla -->
<!DOCTYPE html>
<html>
<head>
    <title>MNLA</title>
</head>
<body>
    <!-- since we've set up the 'message' and 'input' components, we can render them thusly: -->
    <::component.message::>
    <::component.input::>

    <!-- to allow client-side data binding, include this at the end of the body: -->
    <::clientData::>
    <!-- and don't forget your client side scripts: -->
    <script src="/dist.js"></script> <!-- this is from the node_modules/mnla folder -->
    <script src="/js/app.js"></script> <!-- this is from the assets folder -->
</body>
</html>

Client side:

// assets/js/app.js
manila
.component('message', vm => {
    // When this runs, vm (view model) is already populated with the properties
    // that the 'message' controller set on the server side. 
    // You can add additional methods and properties to vm here.
    // Return an object with methods that can be called by other components.
    return {
        update: message => {
            vm.message = message;
        }
    };
})
.component('input', vm => {
    // Here we define the updateMessage method we used in the template as an event listener.
    vm.updateMessage = event => {
        // Inform the message component of the new value using the 'update' method we created.
        manila.components.message.update(event.target.value);
    };
});

Now you can run node index, and open up http://localhost:1337. The html is populated with the "hello, world!" message even before the client side javascript runs, and it stays up-to-date as you update the input.