New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

framework-factory

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

framework-factory

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

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

#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

Keywords

FAQs

Package last updated on 16 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc