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

framework-factory

v1.1.1

Published

A wonderful factory framwork for creating modern object oriented javascript libraries.

Downloads

16

Readme

#Framework Factory#

Framework factory is a tiny, well-designed and yet powerful factory framework for developing modern Object Oriented JavaScript based class libraries, frameworks and applications. Its pluggable architecture and amazing combination of tools (configuration handling, read-only members, events, properties, class inheritance, and much more) gives you enough power to create robust applications which are compatible with your favorite JavaScript library (jQuery, mooTools, underscore), and your favorite platform (Modern Browsers, NodeJS).

Following example shows how a simple farmework called myFramework is created.

Create a new Framework called myFramework through FrameworkFactory.create function. This function accepts configuration object.

var myFramework = FrameworkFactory.create({
    name: "myFramework",
    version: "1.0.0"
});

Create new class called Person within myFramework namespace.

myFramework.Person = myFramework.Class({

    //An attribute called firstName with default value first-name.
    firstName: myFramework.attribute("first-name"),

    //An attribute called lastName with default value last-name.
    lastName: myFramework.attribute("last-name"),

    //A readonly field fullName which returns fullName. Readonly fields
    //can not be changed directly.
    fullName: myFramework.readonly({
        get: function () {
            return this.firstName + " " + this.lastName;
        }
    }),

    //Represents an event which is fired when person starts working.
    start: myFrmaework.event();

    //Person starts working
    work: function () {
        this.trigger("start");
    }

});

Create another class called myFramework.Employee which is derived from myFramework.Person.

myFramework.Employee = myFramework.Person.extend({

    department: myFramework.readonly(),

    //Define employeeCode property which sets the department
    //info based on its value.
    employeeCode: myFramework.property({
        get: function () {
            return this._employeeCode;
        },
        set: function(v) {
            if (v !== this._employeeCode) {
                this._employeeCode = v;
                if (employeeCode < 100) {
                    this._department = "Sales";
                }
                else {
                    this._department = "Marketing";
                }

                //Load other properties like firstName, lastName etc from database.
            }
        }
    }),

    //Constructor function, initializes the new instance of
    //myFramework.Employee
    init: function (employeeCode) {

        if (employeeCode) {
            //Initialize an existing employee
            this.employeeCode = employeeCode;
        }
        else {
            throw new Error("Invalid employeeCode");
        }
    },

    //Employee starts working.
    work: fuction() {
        console.log("Employee started working.");

        //Call base class' work function, which will fire "start" event.
        this.base();
    }

});

Some applications of dummy framework myFramework.

var p1 = new myFramework.Person();
p1.firstName = "Peter";
p1.lastName = "Parker";
console.log(p1.fullName); //Prints Peter Parker

p1.fullName = "Peter Thompson"; //Can't set read-only properties

var e1 = new myFramework.Employee(10);
console.log(e1.employeeCode); //Prints 10
console.log(e1.department); //Prints Sales
console.log(e1 instanceof Employee) //Prints true
console.log(e1 instanceof Person) //Prints true
console.log(e1.fullName); //Prints the fullName loaded from the database.

##Licence and Copyright ##

© 2011-2017 Maniar Technologies Private Limited, MIT license