src/etc/components.js
function (componentDescription) {
                var i = components.length,
                    app;

                // Old-school declaration
                // > franky.Component.extend({
                //  id: 'hello',
                //  init: function () {
                //      console.log('hello');
                //  }
                // });
                if (franky.isObject(componentDescription)) {
                    app = franky.beget(franky.ComponentBase, componentDescription);
                    // Short form declaration
                    // > franky.Component.extend('hello', function () {
                    //      console.log('hello');
                    // });
                } else if (franky.isString(componentDescription) && franky.isFunction(arguments[1])) {
                    app = franky.beget(franky.ComponentBase, {
                        id: componentDescription,
                        init: arguments[1]
                    });
                    // Dependencies injection form declaration
                    // > franky.Component.extend('hello', ['$logger', function ($logger) {
                    //      $logger.say('hello');
                    // }]);
                } else if (franky.isString(componentDescription) && franky.isArray(arguments[1])) {
                    var args = arguments[1];
                    app = franky.beget(franky.ComponentBase, {
                        id: componentDescription,
                        init: function () {
                            var deps = franky.filter(args, function (item) {
                                return franky.isString(item);
                            });
                            deps = franky.map(deps, function (serviceName) {
                                if (!services[serviceName]) {
                                    throw new Error('Service ' + serviceName + ' hasnt defined');
                                }
                                return services[serviceName]();
                            });
                            var defs = franky.filter(args, function (item) {

                                return franky.isFunction(item);
                            });
                            if (defs.length > 1) {
                                throw new Error('Too much declaration functions');
                            }
                            defs[0].apply(this, deps);
                        }
                    });
                } else {
                    throw new Error('Unknown definition structure, try to use extend("yourName", function() { ... init code ... })');
                }

                if (!app.id) {
                    franky.error('extend method expects id field in description object');
                }

                components.push(app);
                // fill index
                componentsIndex[app.id] = i;
                return components[i];

            }
function (componentDescription) {
                var i = components.length,
                    app;

                // Old-school declaration
                // > franky.Component.extend({
                //  id: 'hello',
                //  init: function () {
                //      console.log('hello');
                //  }
                // });
                if (franky.isObject(componentDescription)) {
                    app = franky.beget(franky.ComponentBase, componentDescription);
                    // Short form declaration
                    // > franky.Component.extend('hello', function () {
                    //      console.log('hello');
                    // });
                } else if (franky.isString(componentDescription) && franky.isFunction(arguments[1])) {
                    app = franky.beget(franky.ComponentBase, {
                        id: componentDescription,
                        init: arguments[1]
                    });
                    // Dependencies injection form declaration
                    // > franky.Component.extend('hello', ['$logger', function ($logger) {
                    //      $logger.say('hello');
                    // }]);
                } else if (franky.isString(componentDescription) && franky.isArray(arguments[1])) {
                    var args = arguments[1];
                    app = franky.beget(franky.ComponentBase, {
                        id: componentDescription,
                        init: function () {
                            var deps = franky.filter(args, function (item) {
                                return franky.isString(item);
                            });
                            deps = franky.map(deps, function (serviceName) {
                                if (!services[serviceName]) {
                                    throw new Error('Service ' + serviceName + ' hasnt defined');
                                }
                                return services[serviceName]();
                            });
                            var defs = franky.filter(args, function (item) {

                                return franky.isFunction(item);
                            });
                            if (defs.length > 1) {
                                throw new Error('Too much declaration functions');
                            }
                            defs[0].apply(this, deps);
                        }
                    });
                } else {
                    throw new Error('Unknown definition structure, try to use extend("yourName", function() { ... init code ... })');
                }

                if (!app.id) {
                    franky.error('extend method expects id field in description object');
                }

                components.push(app);
                // fill index
                componentsIndex[app.id] = i;
                return components[i];

            }
function ( componentDescription ) { var i = components . length , app ; // Old-school declaration // > franky.Component.extend({ //  id: 'hello', //  init: function () { //      console.log('hello'); //  } // }); if ( franky . isObject ( componentDescription ) ) { app = franky . beget ( franky . ComponentBase , componentDescription ) ; // Short form declaration // > franky.Component.extend('hello', function () { //      console.log('hello'); // }); } else if ( franky . isString ( componentDescription ) && franky . isFunction ( arguments [ 1 ] ) ) { app = franky . beget ( franky . ComponentBase , { id : componentDescription , init : arguments [ 1 ] } ) ; // Dependencies injection form declaration // > franky.Component.extend('hello', ['$logger', function ($logger) { //      $logger.say('hello'); // }]); } else if ( franky . isString ( componentDescription ) && franky . isArray ( arguments [ 1 ] ) ) { var args = arguments [ 1 ] ; app = franky . beget ( franky . ComponentBase , { id : componentDescription , init : function ( ) { var deps = franky . filter ( args , function ( item ) { return franky . isString ( item ) ; } ) ; deps = franky . map ( deps , function ( serviceName ) { if ( ! services [ serviceName ] ) { throw new Error ( 'Service ' + serviceName + ' hasnt defined' ) ; } return services [ serviceName ] ( ) ; } ) ; var defs = franky . filter ( args , function ( item ) { return franky . isFunction ( item ) ; } ) ; if ( defs . length > 1 ) { throw new Error ( 'Too much declaration functions' ) ; } defs [ 0 ] . apply ( this , deps ) ; } } ) ; } else { throw new Error ( 'Unknown definition structure, try to use extend("yourName", function() { ... init code ... })' ) ; } if ( ! app . id ) { franky . error ( 'extend method expects id field in description object' ) ; } components . push ( app ) ; // fill index componentsIndex [ app . id ] = i ; return components [ i ] ; }
Cornerstone of Component moodule - method for creating new components
Cornerstone of Component moodule - method for creating new components