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

lucy-live

v0.1.3

Published

A library for live coding.

Downloads

6

Readme

Lucy Live Build Status

Part of lucidity project.

Live coding support for node.js

Replace 'require' by 'live.require' to constantly update the required code or assets as the source file changes.

Usage example:

const live = require ( 'lucy-live' )

// expects foo.js library to return "obj"
live.load
( 'foo.js'
, function ( obj )
  {
    console.log ( 'foo changed: ' + obj )
  }
)

live.path
( 'image.jpg'
, function ( imgPath )
  { // do something with new image taking
    // care of Browser cache
  }
)

// Start listening for changes in '.'
live.watch ( '.' )

The module definition needs to take into account that it may be reloaded by reusing module.exports and updating it. Simply exporting a new module will not work because the newly created module will not be linked to existing objects.

Example of a module exporting a simple Person class where methods are live coded. The code shown here is just one way to implement this behaviour. The only thing to notice is that loaded is false on first load and true on reload:

// Person.js

if ( ! exports.loaded )
{ // Initial code loading is used to create a simple function wrapping a call
  // to an initialize method.
  module.exports = function ()
  { this.init.apply ( arguments )
  }
}
// Code from here is executed on every file change.
const Person = module.exports.prototype

Person.init = function ( name )
{ this._name = name
}

Person.sayHello = function ()
{ console.log ( `Hello, I am ${ this._name }.` )
}

Person usage:

const live   = require ( 'lucy-live' )
const Person = live.require ( './Person' )

let o = new Person ( 'Georg Groddeck' )
o.sayHello ()

setTimeout
( function ()
  { o.sayHello () // will call the updated 'sayHello' method
  }               // when Person.js is changed
, 2
)

// To only call a method when the file is loaded (always called at least once)
// one can use live.path:
live.path
( './Person'
, function ( path )
  { console.log ( `Path '${ path }' changed.` )
    o.sayHello ()
  }
)

// Start watching for changes in this file's directory.
live.watch ( '.' )

Real world example of GLSL shader live coding (taken from Lucidity.

const ShaderEffect = require ( 'lucy-compose' ).ShaderEffect
const THREE = require ( 'three' )
const live  = require ( 'lucy-live' )

if (!exports.loaded) {
  // On first load, we create the effect
  module.exports = new ShaderEffect
}
const self = module.exports

// We simply update the shaders when the glsl files change.

live.read
( './vert.glsl'
, function ( s )
  { self.material.vertexShader = s
    self.material.needsUpdate  = true
  }
)

live.read
( './frag.glsl'
, function ( s )
  { self.material.fragmentShader = s
   self.material.needsUpdate    = true
  }
)

// We could customize a method like this:
self.render = function ( context, target )
{
  // ...
}

Installation

npm install lucy-live --save

Tests

npm test

Contributing

Please use 'jessy style'.

Add unit tests for any new or changed functionality.

Release History

  • 0.1.3 (2015-09-22) Better documentation.
  • 0.1.2 (2015-09-22) Compatible with latest version of node.js.
  • 0.1.1 (2015-09-02) NPM readme fix.
  • 0.1.0 (2015-09-02) Initial release.