cartodb/lib/assets/javascripts/builder/components/onboardings/generic/generic-onboarding-launcher.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-06-15 10:58:47 +08:00
var _ = require('underscore');
var GenericOnboardingLauncher = function (launcherOpts, viewOpts) {
var _view;
var _onboardingNotification;
var _notificationKey;
var _onboardings;
var _viewOpts;
if (!launcherOpts || !launcherOpts.view) {
throw new Error('view is required');
}
if (!launcherOpts.onboardingNotification) {
throw new Error('onboardingNotification is required');
}
if (!launcherOpts.notificationKey) {
throw new Error('notificationKey is required');
}
if (!launcherOpts.onboardings) {
throw new Error('onboardings is required');
}
if (!viewOpts) {
throw new Error('viewOpts is required');
}
_view = launcherOpts.view;
_onboardingNotification = launcherOpts.onboardingNotification;
_notificationKey = launcherOpts.notificationKey;
_onboardings = launcherOpts.onboardings;
_viewOpts = viewOpts;
return {
launch: function (launchOpts) {
if (!_onboardingNotification.getKey(_notificationKey)) {
_onboardings.create(function () {
var extendedViewOptions = _.extend(_viewOpts, {
onboardingNotification: _onboardingNotification,
notificationKey: _notificationKey
});
return new _view(_.extend(extendedViewOptions, launchOpts));
});
}
}
};
};
module.exports = GenericOnboardingLauncher;