UNPKG

mixpanel-browser

Version:

The official Mixpanel JavaScript browser client library

133 lines (119 loc) 3.45 kB
/* eslint camelcase: "off" */ import { _ } from './utils'; /** @const */ var SET_ACTION = '$set'; /** @const */ var SET_ONCE_ACTION = '$set_once'; /** @const */ var UNSET_ACTION = '$unset'; /** @const */ var ADD_ACTION = '$add'; /** @const */ var APPEND_ACTION = '$append'; /** @const */ var UNION_ACTION = '$union'; /** @const */ var REMOVE_ACTION = '$remove'; /** @const */ var DELETE_ACTION = '$delete'; // Common internal methods for mixpanel.people and mixpanel.group APIs. // These methods shouldn't involve network I/O. var apiActions = { set_action: function(prop, to) { var data = {}; var $set = {}; if (_.isObject(prop)) { _.each(prop, function(v, k) { if (!this._is_reserved_property(k)) { $set[k] = v; } }, this); } else { $set[prop] = to; } data[SET_ACTION] = $set; return data; }, unset_action: function(prop) { var data = {}; var $unset = []; if (!_.isArray(prop)) { prop = [prop]; } _.each(prop, function(k) { if (!this._is_reserved_property(k)) { $unset.push(k); } }, this); data[UNSET_ACTION] = $unset; return data; }, set_once_action: function(prop, to) { var data = {}; var $set_once = {}; if (_.isObject(prop)) { _.each(prop, function(v, k) { if (!this._is_reserved_property(k)) { $set_once[k] = v; } }, this); } else { $set_once[prop] = to; } data[SET_ONCE_ACTION] = $set_once; return data; }, union_action: function(list_name, values) { var data = {}; var $union = {}; if (_.isObject(list_name)) { _.each(list_name, function(v, k) { if (!this._is_reserved_property(k)) { $union[k] = _.isArray(v) ? v : [v]; } }, this); } else { $union[list_name] = _.isArray(values) ? values : [values]; } data[UNION_ACTION] = $union; return data; }, append_action: function(list_name, value) { var data = {}; var $append = {}; if (_.isObject(list_name)) { _.each(list_name, function(v, k) { if (!this._is_reserved_property(k)) { $append[k] = v; } }, this); } else { $append[list_name] = value; } data[APPEND_ACTION] = $append; return data; }, remove_action: function(list_name, value) { var data = {}; var $remove = {}; if (_.isObject(list_name)) { _.each(list_name, function(v, k) { if (!this._is_reserved_property(k)) { $remove[k] = v; } }, this); } else { $remove[list_name] = value; } data[REMOVE_ACTION] = $remove; return data; }, delete_action: function() { var data = {}; data[DELETE_ACTION] = ''; return data; } }; export { SET_ACTION, SET_ONCE_ACTION, UNSET_ACTION, ADD_ACTION, APPEND_ACTION, UNION_ACTION, REMOVE_ACTION, DELETE_ACTION, apiActions };