Last active
October 19, 2016 13:44
-
-
Save jonfazzaro/3b4605f3a9efce069a3f67df053f6be8 to your computer and use it in GitHub Desktop.
A syntactic sugar packet for Squire.js (https://github.com/iammerrick/Squire.js/).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(function (require) { | |
var Squire = require('Squire'); | |
return { | |
load: load | |
}; | |
function load(modelId, dependencies) { | |
var s = new Squire(); | |
addMockedDependencies(s, dependencies) | |
s.store(listed(dependencies)); | |
return resquire(s, modelId); | |
} | |
function resquire(squire, modelId) { | |
var p = $.Deferred(); | |
squire.require([modelId, 'mocks'], function (model, mocks) { | |
p.resolve(model, hash(mocks.store), mocks.store); | |
}); | |
return p; | |
} | |
function hash(store) { | |
var o = {}; | |
for (var moduleId in store) | |
o[simple(moduleId)] = store[moduleId]; | |
return o; | |
} | |
function addMockedDependencies(squire, dependencies) { | |
for (var moduleId in (dependencies || {})) | |
if (dependencies[moduleId]) | |
squire.mock(moduleId, dependencies[moduleId]); | |
} | |
function listed(mocks) { | |
var list = []; | |
for (var id in mocks || []) | |
list.push(id); | |
return list; | |
} | |
function simple(id) { | |
var tokens = id.split('/'); | |
return tokens[tokens.length - 1]; | |
} | |
function toArray(object) { | |
var array = []; | |
for (var property in object) | |
array.push(object[property]); | |
return array; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A syntactic sugar packet for Squire.js.
Turns this
into this.