Git Product home page Git Product logo

freshy's Introduction

freshy

An (admittedly naïve) node module (un|re)loader/refreshener.

Build Status

API

unload(module)

  • module (String) - the module to unload

Completely unload a node module from the cache. Returns true if the module was present in the cache, false if not.

var minimist = require('minimist'),
    freshy = require('freshy');

freshy.unload('minimist'); // true

reload(module)

  • module (String) - the module to reload

Completely unload and reload a given module in place, leaving the new copy in the cache. Returns reloaded module.

var minimist = require('minimist'),
    freshy = require('freshy');

var fresh = freshy.reload('minimist');
console.log(minimist === fresh); // false

freshy(module, [callback])

  • module (String) - the module for which to fetch a fresh instance
  • callback (function, optional) - A function called while the fresh module is the one in cache

Get a fresh instance of a module without disturbing the cached copy. Returns the fresh module instance.

var minimist = require('minimist'),
    freshy = require('freshy');

var fresh = freshy.freshy('minimist');
console.log(minimist === fresh); // false

var mini = require('minimist');
console.log(minimist === mini); // true

And to get a consistent require of modules that require each other, you can use the callback style:

var minimist = require('minimist'),
    freshy = require('freshy');

var alsofresh;
var fresh = freshy.freshy('minimist', function (fresh) {
    alsofresh = require('minimist');

    console.log(fresh === alsofresh); // true
});
console.log(minimist === fresh); // false
console.log(fresh == alsofresh); // true

var mini = require('minimist');
console.log(minimist === mini); // true

This is useful for modules that alter other modules you require. dustjs-linkedin and dustjs-helpers is an example of this.

freshy's People

Contributors

aredridel avatar gabrielcsapo avatar indutny avatar osukaa avatar totherik avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.