Skip to content

Commit

Permalink
fix: segment
Browse files Browse the repository at this point in the history
  • Loading branch information
prxmat committed Jun 4, 2021
1 parent c0a1584 commit 3747ed1
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions dist/@prestashopcorp/segment-vue.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*!
* @prestashopcorp/segment-vue v2.0.0
* @prestashopcorp/segment-vue v2.1.5
* (c) 2021 undefined
* Released under the MIT License.
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('load-script'), require('vue-demi')) :
typeof define === 'function' && define.amd ? define(['load-script', 'vue-demi'], factory) :
(global = global || self, global['@prestashopcorpSegmentVue'] = factory(global.loadScript, global.vueDemi));
}(this, (function (loadScript, vueDemi) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('load-script'), require('vue-demi')) :
typeof define === 'function' && define.amd ? define(['exports', 'load-script', 'vue-demi'], factory) :
(global = global || self, factory(global['@prestashopcorpSegmentVue'] = {}, global.loadScript, global.vueDemi));
}(this, (function (exports, loadScript, vueDemi) { 'use strict';

loadScript = loadScript && loadScript.hasOwnProperty('default') ? loadScript['default'] : loadScript;

Expand Down Expand Up @@ -117,12 +117,22 @@
return window.analytics;
}

var useSegment = function useSegment() {
var _getCurrentInstance = vueDemi.getCurrentInstance(),
$segment = _getCurrentInstance.appContext.config.globalProperties.$segment;

if (!$segment) {
throw new Error("Segment not provided");
}
return $segment();
};

/**
* Vue installer
* @param {Vue instance} Vue
* @param {Object} [options={}]
*/
function install(Vue) {
var install = function install(Vue) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

var config = Object.assign({
Expand All @@ -145,8 +155,8 @@
});
}

if (vueDemi.isVue2 && window.analytics) {
if (!Vue.hasOwnProperty($segment) && !Vue.prototype.hasOwnProperty("$segment")) {
if (vueDemi.isVue2) {
if (!Vue.hasOwnProperty("$segment") && !Vue.prototype.hasOwnProperty("$segment")) {
Object.defineProperty(Vue, "$segment", {
get: function get() {
return window.analytics;
Expand All @@ -159,7 +169,7 @@
});
}
} else {
Vue.provide('$segment', window.analytics);
vueDemi.provide("$segment", window.analytics);
Vue.config.globalProperties.$segment = function () {
return window.analytics;
};
Expand All @@ -177,10 +187,13 @@
// },
// });
// }
}
};

var index = { install: install };

return index;
exports.default = index;
exports.useSegment = useSegment;

Object.defineProperty(exports, '__esModule', { value: true });

})));

0 comments on commit 3747ed1

Please sign in to comment.