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

lava-class-manager

v1.1.0

Published

Fast and beautiful class system

Downloads

2

Readme

#Standalone version of Lava.ClassManager

One of the fastest and most convenient class systems in the world.

Quick facts:

  • Classes can be generated on server and in browser
  • Supports multiple inheritance
  • Monomorphism optimizations
  • Has powerful features like run-time prototype patching and shared members

Docs:

Standalone version is self-contained (it does not have any dependencies, like the main framework).

##Performance

ClassManager can generate classes in two modes, depending on is_monomorphic switch. Monomorphic mode generates classes with slower constructors, but fast method calls (due to the fact, that all class instances will have the same internal type, reducing method polymorphism). Polymorphic mode generates fast constructors with slower method calls.

High quality polymorphic tests are coming soon...

Meanwhile you can have a look at the following tests, which are not 100% correct:

  • ClassManager vs native classes (counter is overflown, and no polymorphism)
  • Hybrid test of a dozen of class systems (incorrectly mixes class creation time and method calls)

Constructor generation performance

Class generation in ClassManager is slower in comparison to other class systems, but:

  • it's still very fast, so you can comfortably use it in browser
  • generated classes are extremely fast
  • classes can be generated on server (like with CoffeeScript or TypeScript preprocessors)

There will be no performance tests for class constructor generation time, cause it's not fair to compare class systems with language preprocessors.

Class construction performance

Coming soon...

Method call performance

Coming soon...

##Usage example

You may either require("lava-class-manager") (in Node.js environment) or include it directly in browser. You will get a partial copy of Lava object with ClassManager and it's dependencies.

// in Node.js environment:
// var Lava = require("lava-class-manager");
// in browser:
// <script src="path/to/ClassManager/lib/class_manager.js"></script>

// namespaces is a must
Lava.ClassManager.registerRootNamespace('global', window);

Lava.ClassManager.define(
'global.Animal',
{
	name: null,
	steps: 0,
	food: [], // will NOT be shared across class instances
	
	// constructor
	init: function(name) {
		this.name = name;
	},
	walk: function() {
		this.steps++;
	}
});

Lava.ClassManager.define(
'global.Cat',
{
	Extends: 'global.Animal',
	init: function(name) {
		this.Animal$init(name); // parent method call
	}
});

var cat = new Cat("Garfield");
cat.walk();

Lava.instanceOf(cat, "global.Animal");

##Limitations

While using compression - you can not mangle method names in class bodies, cause this will break inheritance. Good-behaving compression tools will not do it, anyway.

##Changelog

1.1.0

  • [Feature] Added Lava.ClassManager.is_monomorphic property (true by default) - in this mode generated constructors will preallocate all class properties to reduce function polymorphism. This will make construction slower, but operation will be faster. Each _cClassData now has is_monomorphic property, which indicates if it was built in monomorphic mode.
  • [Feature] Added loadClasses() and loadSkeletons() convenience methods
  • [Refactoring] RegExp objects are now moved to prototype. If you want to have unique copy of regular expression object for each class instance - then you should assign it in constructor.
  • [Refactoring] Changed format of exported classes: now it exports both references and own_references arrays - you should delete either one of them. If you leave references - then you will get large, but fast and truly monomorphic class with it's own methods. In most scenarios you will want to leave own_references for smaller output.
  • [Refactoring] Changed format of generated skeleton (if you did not export classes - then ignore)
  • [Refactoring] Renamed ClassManager#INLINE_SIMPLE_ARRAYS -> inline_simple_arrays
  • [Refactoring] Added Lava.define - proxy to Lava.ClassManager.define
  • [Fix] Fixed several serialization bugs.

Light performance improvements.

1.0.3

  • [Fix] Fixed an issue in Node.js environment, when generated constructor was invalid. Slightly improved performance.

1.0.2

  • [Feature] Added possibility to store arrays in Shared
  • [Refactoring] Removed _cClassData#level as redundant
  • [Refactoring] exportClass now produces slightly less data
  • [Refactoring] Now it ensures that members, which are shared in parent class, are not marked as shared in inherited class
  • [Refactoring] Shared objects are now copied directly from class body, instead of shallow copy. May matter, if you create class instances before calling ClassManager#exportClass, otherwise ignore

1.0.1

  • Added Lava.instanceOf() method - analog of instanceof JS operator