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

chuck-configurator

v1.0.0

Published

A pseudo DI factory for the [ChucK language](http://chuck.cs.princeton.edu/).

Downloads

4

Readme

The Configurator

A pseudo DI factory for the ChucK language.

Usage

Registering with the ObjectFactory

You can register any type as part of the ObjectFactory by calling the Register static method. For example:

public class ThingBase { }
public class JustAThing extends ThingBase { }
public class SuperCoolThing extends ThingBase { }

ObjectFactory.Register("JustAThing", new JustAThing);
ObjectFactory.Register("SuperCoolThing", new SuperCoolThing);

Note: since ChucK (as far as I know) doesn't have reflection, registration uses magic strings and and concrete instances. You should be careful that what you register won't interfere with normal execution by handling/creating events or by using a large chuck of memory.

Getting Instances

The ObjectFactory has two non-public methods _GetInstance and _GetConfiguredInstance. Since these are non-public you will have to sub-class the ObjectFactory with your own strongly-typed implementation. For example:

public class ThingFactory extends ObjectFactory
{
  fun ThingBase GetConfiguredThing()
  {
    return _GetConfiguredInstance("Thing") $ ThingBase;
  }

  fun SuperCoolThing GetSuperCoolThing()
  {
    return _GetInstance("SuperCoolThing") $ SuperCoolThing;
  }

  fun JustAThing GetJustAThing()
  {
    return _GetInstance("JustAThing") $ JustAThing;
  }

  static ThingFactory @ _thingFactory;
  fun static ThingFactory Instance()
  {
    if(_thingFactory == null)
    {
      new ThingFactory @=> _thingFactory;
    }
    return _thingFactory;
  }
}
ThingFactory.Instance();

Note: I'm fairly unhappy with the whole registration/retrieval thing so it is fairly likely to change in an upcoming release

Configuring the implementations

Before/During/After ObjectFactory registration you can set the default implementations. This is done by calling the UseDefault static method. For example:

// Note: "Thing" is pretty arbitrary. It could be "things", or "t" or even "I miss reflection..."
ObjectFactory.UseDefault("Thing", "SuperCoolThing");

The default implementation will only be used if a non-default implementation is not chosen. For example:

ObjectFactory.UseDefault("Thing", "SuperCoolThing");

ThingFactory.Instance().GetConfiguredThing() // returns SuperCoolThing implementation
ObjectFactory.UseDefault("Thing", "SuperCoolThing");
ObjectFactory.Use("Thing", "JustAThing");
ObjectFactory.UseDefault("Thing", "SuperCoolThing");

ThingFactory.Instance().GetConfiguredThing() // returns JustAThing implementation
The Configurator

Basically just a wrapper for code I found myself commonly writing around configuration and DI. It has a single static method Configure which parses an options array and configures the ObjectFactory. For example:

[ "Thing", "JustAThing",
  "AnotherKey", "AnotherValue" ] @=> string args[];
Configurator.Configure(args);

/*  ObjectFactory will have received the following calls
*   ObjectFactory.Use("Thing", "JustAThing");
*   ObjectFactory.Use("AnotherKey", "AnotherValue");
*/

This makes it easy to configure ChucK from the command line. For example:

string args[0];
for(int i; i < me.args(); i++)
{
  args << me.arg(i);
}

Configurator.Configure(args);