
Product
Introducing Pull Request Stories to Help Security Teams Track Supply Chain Risks
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
framework-factory
Advanced tools
A wonderful factory framwork for creating modern object oriented javascript libraries.
#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
FAQs
A wonderful factory framwork for creating modern object oriented javascript libraries.
We found that framework-factory demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.