all files / src/ index.js

100% Statements 19/19
100% Branches 4/4
100% Functions 3/3
100% Lines 9/9
1 branch Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39                                                             
/*
 * Copyright (c) 2015 TechnologyAdvice
 */
 
// Libs
import { model, obey } from './lib/model'
import { adapter } from './lib/adapter'
import _ from 'lodash'
 
/**
 * Adds plugins for extending core functionality
 * @param {Function} plugin The plugin function
 */
const pluginFn = function(plugin) {
  this[plugin.name] = plugin
}
 
/**
 * Binds model and adapter to make usable entity
 * @param {String} modelName The name of the model
 * @param {String} adapterName The name of the adapter
 */
const use = (modelName, adapterName) => {
  // Initialize model and adapter
  const m = model.init(modelName)
  const a = adapter.init(adapterName)
  // Add adapter name to returned model
  m.adapter = adapterName
  // Return extended (in case model has arbitrary properties/methods)
  return _.extend(a, m, { plugin: pluginFn })
}
 
/**
 * Main modli object
 */
export {
  use, model, adapter, obey
}