0.2.8 • Published 9 years ago

st8less v0.2.8

Weekly downloads
1
License
MIT
Repository
-
Last release
9 years ago

Coverage Status Code Climate

What is this

St8less allows to extract functions by specified criteria from your source files. These functions could be placed to separate file and will be addressed via some globally accessed object. It could be useful for hot-swap of those functions, for example - LiveReload.

How it looks like

File1:

var Page1 = {
    controller: function () {
        this.count = 5;
    },
    view: function (c) {
        '__stateless';
        return m('div', 'count is ' + c.count);
    }
};

File2:

function myRand() {
    '__stateless';
    return Math.random();
};

After applying extractor with default settings we get the following:

File1:

 var Page1 = {
    controller: function () {
        this.count = 5;
    },
    view: function (c) {
        return MyGlobal.abc.view0.apply(this, [c, m]);
    }
};

File2:

 function myRand() {
    return MyGlobal.abc.myRand1.apply(this, [Math]);
}

Extracted:

MyGlobal.abc = {};

MyGlobal.abc.view0 = function (c, m){
    '__stateless';
    return m('div', 'count is ' + c.count);
}

MyGlobal.abc.myRand1 = function (Math){
    '__stateless';
    return Math.random();
}

How to use

 var ex = new Extractor();
 ex.parse(fs.readFileSync('file1.js'), function (err, changed) {
   fs.writeFileSync('file1_changed.js', changed);
   ex.parse(fs.readFileSync('file2.js'), {prefix: "functions_from_file2_"}, function (err, changed) {
     fs.writeFileSync('file2_changed.js', changed);
     ex.done(function (err, extracted) {
       fs.writeFileSync('extracted.js', extracted);
     });
   });
 });

Extractor options:

  • criteria - which functions shall be extracted. Is a function which accepts functionDefinition parameter, which is an object with following properties:
    • name - function name (or property/variable name that holds the function)
    • attribute - attribute defined as string expression at begining of function, like __stateless in example above
    • paramNames - argument names
    • externalVariables - variable/fn names used in function but not declared inside By default extractor looks for functions with __stateless attribute
  • objectName - object ot store extracted functions. Default is St8less
  • globalName - global object to use in calls. Default is window

Usage

Used by mithril reload plugin

0.2.8

9 years ago

0.2.7

9 years ago

0.2.6

9 years ago

0.2.5

9 years ago

0.2.4

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago