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

deja-view

v0.3.0

Published

Simple and declarative client-side templating.

Downloads

6

Readme

deja Build Status

Declarative and reactive javascript templating.

  • Pure html and js.
  • Reactive data bindings. Syncs data with individual nodes in the dom.
  • No view logic allowed (put it in your js).
  • No dependencies.
  • Works with IE6+, Chrome, Firefox, Safari, and Opera

Similar to reactive.

usage

Install with:

npm install deja-view

Instantiate like:

var deja = require('deja');
var view = deja.view(data_model);
view.render(element);

Where data_model is an object containing your view's data that will emit events when its properties are changed.

element can be a DOM Node, an array of Nodes, or a NodeList. You can repeatedly render the view into any number number of elements.

interpolation

We use the dj-text attribute to indicate we want to interpolate something into the text of the element.

<p --text='greeting'>Some default text<p>
var view = deja.view({greeting: 'hallo welt!'});
view.render('p');

Result:

<p>hallo welt!</p>

interpolating attributes

Use dj-{attr} to set that element's attributes using your view data. Classes will be appended while all other attributes will be written over.

<a class='account-link' dj-class='status'>Your Account</a>
var view = deja.view({status: 'invalid'})
view.render('.account-link');

The above renders to:

<a class='account-link invalid'>Your Account</a>

Other attributes are written over:

<a class='account-link' dj-data-id='account.id'>Your Account</a>
var view = deja.view({account: {id: 420}});
view.render('.account-link');

Renders to:

<a class='account-link' data-id='420'>Your Account</a>

loops

Use the dj-each attribute and access each element using each

<div dj-each='users'>
	<p dj-text='each.name'></p>
	<p dj-text='each.status'></p>

	<ul dj-each='each.comments'>
		<li>
			<span dj-text='each'></span>
		</li>
	</ul>
</div>

To refer to the element itself within the loop, just use each.

dynamic changes

If your data object emits change {property} events, then deja will automatically sync your changed data into the DOM.

deja only syncs data to the nodes that are bound to them without re-rendering anything else.

For example: if you have a table of users with checkboxes next to each row, then the checkboxes will not be reset when the data updates.

clearing memory

You can call view.clear() (where view is an instance of deja.view) to clear out all listeners, free up memory, and reset the DOM.

configuration

custom subscriptions/listeners

By default, deja listens for events on your model using model.on('change ' + prop, render_func). You can use deja.config to customize this. For example, if you wanted to instead do model.bind(prop, render_func), you can do:

deja.config({
	listen: function(model, prop, render_func) {
		model.bind(prop, render_func);
	}
});

custom data access

By default, deja uses data[property] to access your data. You can custom this using deja.config. For example, to change the accessor to model.get(property), you can do:

deja.config({
	get: function(model, property) {
		return model.get(property);
	}
});

custom attribute prefix

Instead of 'dj-', you can use your own custom prefix for deja attributes. For example, to have deja recognize all attributes with the example prefix data-tmpl-, simply do:

deja.config({
	prefix: 'data-tmpl-'
})