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

lifecycle

v1.0.4

Published

Lifecycle.js provides conventions and helpers to manage the life cycles of Javascript instances.

Downloads

5,718

Readme

Lifecycle.js provides conventions and helpers to manage the life cycles of Javascript instances.

#Download Latest (1.1.2):

Please see the release notes for upgrade pointers.

###Module Loading

Lifecycle.js is compatible with RequireJS, CommonJS, Brunch and AMD module loading. Module names:

  • 'lifecycle' - lifecycle.js.

Introduction

If you need to write code that manages the lifecycle of some javascript objects, but you don't know ahead of time what type of lifecycle model they implement, Lifecycle.js is for you!

A good example of this is Backbone.Articulation. Backbone.Articulation will reconstruct instances of Dates or custom classes within you Backbone.Model's attributes irregardless of what lifecycle model they use (as long as they use one of the known conventions!)

LC.own and LC.disown

Manages the lifecycle of individual instances, objects, arrays, and object properties that comply with some lifecycle conventions:

  • clone() and destroy()
  • retain() and release()
  • clone() and Javascript memory management
  • plain old JSON

Examples:

Run time determination of the correct lifecycle for an instance:

instance = new MyClass()
owned_copy_instance = LC.own(instance)       # you don't need to know whether MyClass needs to get cloned, retained, etc
...
LC.disown(owned_copy_instance)               # you don't need to know whether MyClass needs to get destroyed, released, etc

It also works for Javascript collection types:

# works for arrays containing instances or primitive types
an_array = [new Object(), ‘hello’, new Object()]
owned_copy_array = LC.own(an_array)
...
LC.disown(an_array)

# works for objects whose properties contain instances or primitive types
an_object = {one: new Object(), two: new Object(), three: ‘there’}
owned_copy_object = LC.own(an_object, {properties:true})
...
LC.disown(an_object);

LC.RefCountable

Very basic implementation following the Coffeescript class pattern for a reference countable class.

Examples:

CoffeeScript classes:

class MyClass extends LC.RefCountable
  constructor: ->
    super
    @is_alive = true
  __destroy: ->
    @is_alive = false

instance = new MyClass()  # ref_count = 1
instance.retain()         # ref_count = 2
instance.release()        # ref_count = 1
instance.release()        # ref_count = 0 and __destroy() called

JavaScript classes using extend:

var MyClass = LC.RefCountable.extend({
  constructor: function() {
    LC.RefCountable.prototype.constructor.apply(this, arguments);
    this.is_alive = true;
  },
  __destroy: function() {
    this.is_alive = false;
  }
});

var instance = new MyClass();   // ref_count = 1
instance.retain();              // ref_count = 2
instance.release();             // ref_count = 1
instance.release();             // ref_count = 0 and __destroy() called

Building, Running and Testing the library

###Installing:

  1. install node.js: http://nodejs.org
  2. install node packages: 'npm install'

###Commands:

Look at: https://github.com/kmalakoff/easy-bake