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

mem.js

v0.3.0

Published

JavaScript memory management library

Downloads

6

Readme

Mem.js

Build Status

JavaScript memory management library. Works well with Backbone.js apps

Intro

Mem.js manages functions and objects. It allows save, get and cleanup outdated instances.

It helps reuse views / models / widgets / functions in your app. Mem.js allows to share stored objects and reuse cached instances.

API

Mem.set

Store object / function etc in Mem.js for next reusage. If object is function creates new function instance.

If object with same name and params already exist it will be reused (new instance will not be created).

All objects were set will not be removed next manage. Mem.set removes objects from next cleanup list.

####Arguments

Unique name

Function / object etc to store

Arguments to be transfered to Function constructor

var View = Backbone.View({});

// On set returns new stored function instance or object
var headerViewIns = Mem.set('headerView', View, {el: 'body'});

Mem.get

Returns stored objects from Mem.js

Argument

Unique name

var headerViewIns = Mem.get('headerView');

Mem.unset

Removes stored objects from Mem.js, calls remove and dispose methods automatocally.

Argument

Unique name (not required)

Mem.set('headerView', View, {el: 'body'});

// Removes headerView
Mem.unset('headerView');

Without arguments unsets all stored objects.

Mem.set('headerView', View, {el: 'body'});
Mem.set('headerModel', Model, {name: 'Artyom'});

// Removes headerView and headerModel
Mem.unset();

Mem.reset

Unsets stored functions and creates new one with same parameters.

Argument

Unique name (not required)

Mem.set('headerView', View, {el: 'body'});

Mem.reset('headerView');

Without arguments resets all stored objects.

Mem.set('headerView', View, {el: 'body'});
Mem.set('headerModel', Model, {name: 'Artyom'});

Mem.reset();

Mem.manage

Manages stored objects, removes outdated.

Removes all outdated objects, change all not outdated object state to outdated.

Mem.set removes objects from next cleanup list.

Simple manage:

Mem.set('headerView', View, {el: 'body'});

// headerView will not be removed
Mem.manage();

// headerView will be removed
Mem.manage();

Manage with set:

var ins1 = Mem.set('headerView', View, {el: 'body'});

// headerView will not be removed
Mem.manage();

// new headerView instance will not be created because Mem.js stored same fn with same params.
// Old instsnse will be returned instead
ins1 = Mem.set('headerView', View, {el: 'body'});

// headerView will not be removed
Mem.manage();

// headerView will be removed
Mem.manage();

Examples

Just Test It

Usage

Require.js AMD

requirejs.config({
  baseUrl: 'static/',
  urlArgs: 'bust=' +  Date.now(),
  paths: {
    underscore: 'assets/js/underscore',
    mem: 'assets/js/mem'
  },

  shim: {
    mem: {
      deps: ['underscore'],
      exports: 'Mem'
    }
  }
});

CommonJS

var Mem = require('mem');

Old style

<script src="assets/js/underscore.js" />
<script src="assets/js/mem.js" />

Bower

bower install mem.js

##Dependencies