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

coffee-factory

v0.1.3

Published

Javascript class Factory generator implemented in Coffeescript.

Downloads

9

Readme

Coffee Factory

Javascript class Factory generator implemented in Coffeescript.

Install

npm install --save coffee-factory

Usage

CommonJS Module

new Factory(klass, maxReuse, ctorArgs...) → Factory Instance

  • klass The class to instantiate when Factory#get() called
  • maxReuse The maximum number of existing instance to keep at any one time. FIFO.
  • ctorArgs Arguments passed to constructor when new instantiations created

Factory#get(initArgs...)klass instance

  • initArgs Arguments passed to .initialize() of instance when Factory#get() called

Factory#put(obj)

  • obj An instance to give the Factory for re-use

Examples

Basic Usage

Factory = require 'coffee-factory'

class User
  name: "default"
  initialize: ->
    @name = ""

UserFactory = new Factory User, 10 # Create the factory

# Get an instance.
# No instances are stored in the factory, so a new one is created
user = UserFactory.get()
console.log user.name # Output: "" - because `.initialize()` is called

user.name = "Foo"

# We no longer want this instance, so let the factory reuse it
UserFactory.put user
user = null
# Normally, garbage collection would delete the object form memory

# Get another instance. There is one stored, so that will be used.
# Before returning, `.initialize` (if it exists) will be called on the instance
user2 = UserFactory.get()
console.log user.name # Output: ""

Passing params to initialize

Factory = require 'coffee-factory'

class User
  name: "default"
  initialize: (@name = "") ->

UserFactory = new Factory User, 10 # Create the factory

user = UserFactory.get "Foo"
console.log user.name # Output: "Foo" - the param was passed to `.initialize()`

Passing params to the constructor

Factory = require 'coffee-factory'

class User
  name: "default"
  constructor: (@name = "") ->

# The "Foo" parameter will be passed to the constructor of User when `.get()` is called
UserFactory = new Factory User, 10, "Foo"

user = UserFactory.get()
console.log user.name # Output: "Foo"

user2 = UserFactory.get()
console.log user2.name # Output: "Foo"

Usage as a Default Constructor system

Factory = require 'coffee-factory'

class User
  isStaff: false
  constructor: (@isStaff) ->

# The "Foo" parameter will be passed to the constructor of User when `.get()` is called
StaffUser = new Factory User, 10, true

ceo = StaffUser.get()
console.log ceo.isStaff # Output: true

Donations

If you'd like to say thanks, buy me a beer by tipping with Dogecoin: DJLZccHAcz19ikSV1D5jY3WdFPU7Nqjmfk