Giter Site home page Giter Site logo

chainit's Introduction

Hi there ๐Ÿ‘‹

Maker

  • TurnShift: Automate Your Team Schedule
  • Tweets @vvoyer: JavaScript, React, Next.js, Building In Public
  • Next.js News: The Next.js Monthly Newsletter (sold)
  • Source Karma: Discover how people react to you on GitHub ๐Ÿ‘ (archived)

chainit's People

Contributors

christian-bromann avatar vvo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

chainit's Issues

support for fun(arg, cb) signature when arg is a function

Hi,
it seems

if((typeof args[args.length - 1] === 'function') && (!ctx.constructor || ctx.constructor.name !== 'WebdriverIO' || fnName.indexOf('execute') === -1 || args.length > 1)) {
is a hack to support the case where method accepts a function and a callback as arguments.
There is surely an explicit way to tell chainit how to deal with that particular case ?

fork with fixes, up-to-date queue, improved error handling

Hi,
i've started a fork to mainly improve error handling (with tests)
https://github.com/kapouer/chainit

also with updated dependency on queue 3.

There are some changes that you might not like:

  • removal of timeout for adding depth-0 tasks, see commits for details
  • removal of specific code that has nothing to do with chainit itself (i.e. webdriver conditions)
  • removal of custom error messages (not really needed since error handling is better)

Feel free to merge/cherry-pick commits !
Jรฉrรฉmy.

performance issues

after I upgraded the queue package and brought code back to work chainIt runs much slower after a time (observed in WebdriverJS). I think the problem appeared after commit 394fff482. It is maybe connected with the fact that I start the queue too often (see L35).

new Function(functionBody) gets a function while expection a string.

index.js: Line 82

  Object.keys(Constructor)
    .forEach(function(name) {
      Chain[name] = new Function(Constructor[name]); // <- this throws an error 
    });

The error is:

SyntaxError: Unexpected token (
    at Object.Function (<anonymous>)
    at /Users/username/examples/node_modules/chainit/index.js:82

To reproduce:

var Class = function() {};
Class.prototype.test = function() {};
Class.extend = function() {};

var NewClass = chainit(Class);

chain a subclass

Consider the following inheritance patterns in Javascript:

The classic way:

var Base = function(config) { this.config = config };
Base.prototype.method1 = function(cb) { cb(); };
Base.prototype.method2 = function(cb) { cb(); };

var ChildClass = function(config) { this.config = config; this.prop = true; };
ChildClass.prototype = new Base();
ChildClass.prototype.constructor = ChildClass;

ChildClass.prototype.method3 = function(cb) { cb(); };
ChildClass.prototype.method4 = function(cb) { cb(); };

The constructor-less inheritance using ES5 Object.create

var Base = {
    create: function create() {
       var instance = Object.create(this);
       instance._construct.apply(instance, arguments);
       return instance;
    },
    extend: function extend(properties, propertyDescriptors) {
        propertyDescriptors = propertyDescriptors || {};
         if(properties){
            var simpleProperties = Object.getOwnPropertyNames(properties);
            for (var i = 0, len = simpleProperties.length; i < len; i += 1) {
                var propertyName = simpleProperties[i];
                if(propertyDescriptors.hasOwnProperty(propertyName)) {
                    continue;
                }
                propertyDescriptors[propertyName] =
                    Object.getOwnPropertyDescriptor(properties, propertyName);
            }
        }

        return Object.create(this, propertyDescriptors);
    },
     _construct: function _construct() {},

    method1: function method1(cb) { cb(); },
    method2: function method2(cb) { cb(); }
};

var ChildClass = Base.extend({
    method3: function(cb) { cb(); },
    method4: function(cb) { cb(); }
});

Can you recommend a good way to plug async chaining for ChildClass in both use-cases?

Thanks in advance!

chaining events.EventEmitter.prototype.on

Hi,
i have

function Test() {}
util.inherits(Test, events.EventEmitter);
var ChainableTest = chainit(Test);

i'd like to use chainit on the "on" listener function:

var mytest = new ChainableTest();
mytest.on('ready').load('something')

unfortunately on() never gets called in that case.
Any idea how to achieve this ?

Allow passing of a function([function])

https://github.com/vvo/chainit/blob/master/index.js#L99 shows that if the last argument is a function, we treat that as the callback.

However, consider this scenario:

// We have a callback added onto the function
chainit.add([object], name, function(string){

});

// function is treated as the final callback
chainit.add([object], name, function(string, function){

});

If I were to pass a string, the callback would be implemented for me:

chainit.add([object], name, function(string){

});

// the function gets called
function(string, cb){

});

but because I pass a function, this happens

chainit.add([object], name, function(function){

});

// the function gets called
function(cb){

});

This leads to confusion and means that sometimes it will be necessary to pass an empty function if you don't require a callback.

It would be better if it operated the same way the entire time.

EDIT: it could be fixed by just passing a boolean param to add() if we want to use our function as the cb, or the generated one.

Here is perhaps a better example:

chainit.add([object], 'myFunction', function(param1, callback){
    console.log(param1);
    callback();
})

// Logs out the string, callback is defined
[object].myFunction(string);

// Logs out the function, callback is undefined
[object].myFunction(otherFunction);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.