UNPKG

built.io-browserify

Version:

SDK for Built.io Backend which is compatible with Browserify

44 lines (43 loc) 1.35 kB
var R = require('ramda'); /** * @class Mixin * @classdesc * Built.Mixin should be used to merge Plain JavaScript object, Built.Group or Built.GroupMultiple together * @instance * @description This should be used to mix instances of Built.Group, Built.GroupMultiple and Plain JavaScript object together * @param {Object|Built.Group|Built.GroupMultiple} data Can be 1] Plain JavaScript object 2] Instance of Built.Group 3] Instance of Built.GroupMultiple * @example * // Consider you have a group field 'employee' which has to sub-group 'profile' and 'address' * var profile = Built.Group('profile',{ * name:'John', * gender: 'Male' * }) * var address = Built.Group('address',{ * city:'Mumbai', * area: 'Borivali' * }) * var employee = Built.Mixin(profile, address); * console.log(employee.toJSON()) * // OUTPUT * //{ * // profile:{ * // name:'John', * // gender: 'Male' * // }, * // address:{ * // city:'Mumbai', * // area:'Borivali' * // } * //} * @return {Object} */ module.exports.Mixin = function() { var mixinedObject = {} Array.prototype.forEach.call(arguments, function(currentVal) { if (currentVal._isGroup || currentVal._isGroupMultiple) { mixinedObject = R.mixin(mixinedObject, currentVal.toJSON()) } else mixinedObject = R.mixin(mixinedObject, currentVal); }) return mixinedObject; }