Skip to content

Instantly share code, notes, and snippets.

Lucas Paulger lpaulger

View GitHub Profile
@lpaulger
lpaulger / example.js
Last active Jun 30, 2016
good parameters example
View example.js
//DO
function example(options) {
//this clearly identifies what the expected parameters are
const {
injectedLibrary,
otherThing
} = options;
this.methodOne = function(){
injectedLibrary.doSomething('methodOne')
@lpaulger
lpaulger / example.js
Created Jun 30, 2016
code dilution example
View example.js
function example(options) {
const {injectedLibrary} = options;
//DON'T
this.methodOne = function(){
doSomethingInjectedLibrary('methodOne')
}
this.methodTwo = function(){
doSomethingInjectedLibrary('methodTwo')
@lpaulger
lpaulger / ThingViewModel.test.js
Created Jun 17, 2016
example test with constructor arguments
View ThingViewModel.test.js
describe('when creating a ThingViewModel', function () {
var ctorArgs;
beforeEach(function(){
ctorArgs = {
ThingApi: {
getThings: function(){}
},
ThingUtility: {}
}
});
@lpaulger
lpaulger / ThingViewModel.test.js
Last active Jun 17, 2016
example first test for legacy code
View ThingViewModel.test.js
describe('when creating a ThingViewModel', function () {
it('should return an object', function () {
var thingViewModel = new ThingViewModel();
expect(typeof thingViewModel).toBe('object');
});
});
@lpaulger
lpaulger / MyModule.js
Last active Apr 18, 2016
example module before it's been UMDified
View MyModule.js
'use strict'
var MyModule = {
foo: function() {
//content with external dependency
return $.doSomething();
},
bar: function() {
//content
@lpaulger
lpaulger / MyModule.js
Last active Apr 18, 2016
example UMD module
View MyModule.js
;(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery'], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require('jquery'));
} else {
root.MyModule = factory(root.jQuery);
}
}(this, function($) {
'use strict'
@lpaulger
lpaulger / uglify.js
Created Apr 18, 2016
grunt uglify build configuration
View uglify.js
module.exports = {
options: {
...
},
build: {
files: {
'dist/MyCompanyModules.js': [
...,
'node_modules/MyModule/build/MyModule.js'
...
@lpaulger
lpaulger / package.json
Created Apr 18, 2016
example pacakge.json with module reference
View package.json
{
"name": "MyCompany",
"description": "example package.json",
"version": "0.0.1",
"scripts": {
"start": "grunt watch",
"build": "grunt build",
"test": "grunt test",
"analysis": "grunt analysis"
},
@lpaulger
lpaulger / namepsace-example.js
Created Apr 18, 2016
and example of how to reference module code in old legacy (namespace) javascript code
View namepsace-example.js
window.MyCompany.Utilities = {
foo: window.MyModule.foo,
bar: window.MyModule.bar
}
View knockout.debug.js
(function(undefined){
// (0, eval)('this') is a robust way of getting a reference to the global object
// For details, see http://stackoverflow.com/questions/14119988/return-this-0-evalthis/14120023#14120023
var window = this || (0, eval)('this'),
document = window['document'],
navigator = window['navigator'],
jQueryInstance = window["jQuery"],
JSON = window["JSON"];
(function(factory) {
You can’t perform that action at this time.