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

marionette.morphdom

v0.1.0

Published

Use morphdom with backbone.marionette

Downloads

1

Readme

marionette.morphdom

This is a backbone.marionette mixin to use morphdom in your views.

Using morphdom in your view will allow you to have DOM diffing & patching without changing your template engine as morphdom deals with real DOM and can take String, DOM or V-DOM as input.

When using this mixin, each call to render will patch your view, make it always up to date if render is called after each state change.

Install

npm i marionette.morphdom

Example

import Backone from 'backbone';
import Mn from 'backbone.marionette';
import morphdomMixin from 'marionette.morphdom';

const MyView = Mn.View.extend(morphdomMixin).extend({
    template: data => `<section><h1>${data.title}</h1><p>${data.article}</p></section>`,

    modelEvents: {
        change: 'render'
    },

    initialize: function() {
        this.model = new Backbone.Model({
            title: 'How to keep this view update to date?',
            article: 'You should use marionette morphdom!'
        });
    }

});

export default MyView;

That's it. Anytime your model change, your view will be patched.

FAQ

Why?

Because default Marionette render does innerHTML to update the view.

Is this slower or faster than... ?

If you already update all your view by hand using jquery or vanilla DOM update or tools for data binding like backbone.stickit this might be slower because it will render the all view before patching. The real advantage is that you can drop all your code dealing with manual precise update and develop quicker. See it as a compromise between performance and development speed. Also if your view are not too big and well split and your template engine fast, you should not experience a big performance regression while the gain in development is quite big.

If you are already just calling render in your views, this should improve greatly your app performance.

The other real performance advantage against things like vdom, is that the diffing & patching process is DOM against DOM. There is no intermediary tree or vtree in memory, no steps between.

For more information on morphdom performance see this FAQ

Why I should drop View tagName, className, ... ?

Because those properties are used by Backbone to build the view root el but if you have some classes or attributes in it depending on your view state, those were not updated on render, you had to update it manually. As this mixin only use the content of your template and use the top root node as view el you can drop Backbone.View tagName, className, attributes and stop mix html from view and template.

Why should I use only one root node in my templates?

See above ;)

If my state updates a lot, very fast, how can I prevent the view to be rendered at the same rate?

This mixin comes with the throttleRender property, which is set on false by default. By setting it on true, the render call will be throttled to 16ms. You can also set it to a numerical value, like 150, to throttle the render to 150ms.

Will my regions be erased on each render?

Nope. If it happens, please fill an issue with your case.

Why morphdom and not X?

Because morphdom does one job, only, but does it very well, without making other assumption on your stack for you. You are free to use any template engine as input. You are free to call the render mechanism anytime at the rate you want. You are free to not using it and keep manual update for big, critical views. Also I agree with the author, the DOM is not slow, and you can bet browser vendors will keep making it faster & faster ;)