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

mithril.exitable

v1.2.1

Published

Exit animations for Mithril components: provide controllers with an `exit` hook which will trigger when the component disappears from the virtual DOM (but before it's removed from live DOM), locking the draw process while you perform animations.

Downloads

8

Readme

mithril.exitable.js

Join the chat at https://gitter.im/barneycarroll/mithril.exitable.js

A Mithril wrapper whose controllers gain a new exit hook for outgoing animations. Exitable is intended for use with the Mithril 0 API - it is redundant in (at the time of writing, forthcoming) Mithril 1, thanks to the onbeforeremove hook.

When you bind an exit method to a controller, we observe the output of each draw: as soon as we detect that the corresponding component has been removed from the view, the draw loop is frozen; all your animations execute, and when they're done, Mithril goes about business as usual.

Demos

…suggest more in the issues!

Usage

Exitable is a Mithril wrapper or patch, meaning you need to bring your own Mithril for Exitable to use as a base. Exitable then wraps certain Mithril methods to extend it with its own behaviour, and returns you a patched version of Mithril to use in your application.

This means your original Mithril is untouched, and eg any other Mithril dependent plugins in your codebase will get access to the 'clean' version rather than going through Exitable, in contrast to eg jQuery plugins which modify the core jQuery object.

Which source?

ES6 / CommonJS / Browserify

The Exitable module depends on Mithril being available as a module as mithril. In turn, you should import Exitable instead of plain Mithril.

// ES6
import m from 'mithril.exitable'
// CommonJS
var m = require( 'mithril.exitable' )

ES3

The ES3 version assumes a browser global environment. It will require a Map polyfill – I recommend Andrea Giammarchi's ES6 collections if this is your only outstanding jsnext dependency. You must include Mithril and your Map polyfill (if necessary) before including Exitable. Exitable will then replace the window.m reference:

<script src="https://cdn.rawgit.com/WebReflection/es6-collections/master/es6-collections.js"></script>
<script src="https://cdn.rawgit.com/lhorie/mithril.js/next/mithril.min.js"></script>
<script src="https://cdn.rawgit.com/barneycarroll/mithril.exitable.js/master/src/exitable.es3.js"></script>

Binding exit animations

To register an exit animation, bind a function to the exit key of the controller instance:

var myComponent {
  controller : function(){
    this.exit = myAnimation
  },
  // ...
}

The animation function receives the live DOM element representing the root of the component that's about to be removed from the document.

// ...
    this.exit = function(el){
      // ...
    }
// ...

For convenience, Exitable also provides an enter method hook, so you can define entry and exit animations in the same place.

{
  controller : function(){
    this.enter = function(el){
      // ...
    }
  },
  view : () =>
    m( '.root' )
}

// Is equivalent to

{
  view : () =>
    m( '.root', {
      config : ( el, init ) => {
        if( !init )
          // ...
      }
    } )
}

exit functions

What should the animation do? That's up to you: although I highly recommend Julian Shapiro's Velocity library, which can be supplemented with a UI pack full of pre-registered animations (which are used throughout the demos).

All exit functions must return a 'thenable' so that Exitable knows when all animations are finished in order to resume Mithril's draw loop.

Velocity

Velocity returns thenables by default, which makes exit animations nice and terse, especially with the help of arrow functions:

this.exit = el =>
  Velocity( el, 'fadeOut' )

Other libs

If your tool of choice doesn't return Promises, you can create your own Promise and bind it to the done callback (or whatever hooks the animation library provides):

this.exit = el =>
  new Promise( done =>
    $( el ).fadeOut( done  )
  )

Without Promises

…and if you can't return thenables or use Promises, then you have to make your own thenable. Exitable doesn't depened upon chaining or suchlike, so anything with a then method which executes at the right time will do:

this.exit = function( el ){
  var thenable = { then : function(){} }

  $( el ).fadeOut( thenable.then )

  return thenable
}