UNPKG

code-challenge-7geese

Version:

This is a revised solution for the 7Geese JavaScript Challenge.

38 lines (36 loc) 1.8 kB
/*global require*/ 'use strict'; var handleName = require('./functions/handleName.js'), defaultModel = require('./models/defaultModel.js'), reposCollection = require('./collections/reposCollection.js'); module.exports = function(myConfig) { // if no config is provided, load some default div id names (verbose but includes error checking) myConfig = (typeof myConfig === 'object') ? myConfig : {}; myConfig.repoName = (typeof myConfig.repoName === 'string') ? myConfig.repoName: '7geese'; myConfig.searchTemplateId = (typeof myConfig.searchTemplateId === 'string') ? myConfig.searchTemplateId : 'search_template'; myConfig.searchDivId = (typeof myConfig.searchDivId === 'string') ? myConfig.searchDivId : 'search_div'; myConfig.searchListId = (typeof myConfig.searchListDivId === 'string') ? myConfig.searchListDivId : 'search_list'; myConfig.searchInputId = (typeof myConfig.searchInputId === 'string') ? myConfig.searchInputId : 'search_input'; myConfig.searchClearId = (typeof myConfig.searchClearId === 'string') ? myConfig.searchClearId : 'search_clear'; myConfig.searchSubmitId = (typeof myConfig.searchSubmitId === 'string') ? myConfig.searchSubmitId : 'search_submit'; // create the object prototype myConfig.myObject = { // add helper functions that we can access everywhere else functions: { handleName: handleName, init: function() { } }, // add a default model models: { defaultModel: defaultModel() }, // views will be appended as necessary views: {} }; // now fetch and append collections myConfig.myObject.collections = { reposCollection: reposCollection(myConfig) }; return myConfig.myObject; };