<commit_before>/**
 * @name MbComponent
 * @description
 * Create a new instance of MbComponent
 * @param {DOMElement} componentEl the component element, which will be showed and hidded
 * @param {string} id the component id
 * @param {object} options the component options
 */
function MbComponentFactory (MbComponentInterface, $animate) {
	var MbComponent = MbComponentInterface.extend({
		initialize: function (componentEl, id, options) {
			// defaults
			this.isVisible = false;

			if(angular.isObject(id)) {
				options = id;
				id = undefined;
				angular.extend(this, options);
			}

			if(angular.isDefined(componentEl)) {
				this.setElement(componentEl);
			}

			if(angular.isDefined(id)) {
				this.setId(id);
			}

			this.on('visibleStateChangeSuccess', function () {
				if(this.getVisibleState()) {
					this.emit('visible');
				} else {
					this.emit('notVisible');
				}
			});

			this.on('visibleStateChangeStart', function (visibleState) {
				if(visibleState) {
					this.emit('visibleChangeStart');
				} else {
					this.emit('notVisibleChangeStart');
				}
			});
		},

		/**
		 * @name MbComponent#show
		 * @kind function
		 * @description Show the component
		 * @return {Promise} the animation callback promise
		 */
		show: function () {
			return this.setVisibleState(true);
		},

		/**
		 * @name MbComponent#hide
		 * @kind function
		 * @description Hide the component
		 * @return {Promise} the animation callback promise
		 */
		hide: function () {
			return this.setVisibleState(false);
		},

		/**
		 * @name MbComponent#toggle
		 * @kind function
		 * @description Toggle the component visible state
		 * @return {Promise} the animation callback promise
		 */
		toggle: function () {
			return this.setVisibleState(!this.getVisibleState());
		},

		getHiddenClass: function () {
			return 'mb-hidden';
		},

		getVisibleClass: function () {
			return 'mb-visible';
		},

		getVisibleState: function () {
			return !!this.isVisible;
		},

		/**
		 * @name MbComponent#setVisibleState
		 * @kind function*
		 *
		 * @description Emit `visibleStateChangeStart` event before do anything,
		 * 		then add the visible class and/or remove the hidden, according
		 * 		to the setted visible state param and emit the final event
		 *		`visibleStateChangeSuccess` or `visibleStateChangeError` if we
		 *		got an error.
		 *
		 * @param {Boolean} visibleState the visible state to set
		 *
		 * @return {Promise} the animation callback promise
		 */
		setVisibleState: function (visibleState) {
			var self = this,
					el = this.getElement(),
					promises = [],
					addClass, // Class to add before animate
					removeClass, // Class to remove before animate
					hiddenClass = this.getHiddenClass(),
					visibleClass = this.getVisibleClass(),
					hiddenClassMethod = visibleState ? 'removeClass' : 'addClass';

			this.emit('visibleStateChangeStart', visibleState);

			addClass = visibleState ? visibleClass : hiddenClass;
			removeClass = visibleState ? hiddenClass : visibleClass;

			return $animate.setClass(el, addClass, removeClass).then(function () {
				self.isVisible = visibleState;
				self.emit('visibleStateChangeSuccess');
			}, function (err) {
				self.emit('visibleStateChangeError', err);
			});
		},

		setId: function (id) {
			if(angular.isDefined(this.getId())) {
				throw new Error('You cannot change a component.id more than once');
			}

			Object.defineProperty(this, 'id', {
				value: id,
				writable: false
			});

			return this;
		},

		getId: function () {
			return this.id;
		},

		setElement: function (componentEl) {
			var el = this.componentEl = componentEl,
					isVisible = this.getVisibleState(),
					hiddenClass = this.getHiddenClass();

			if(!el.hasClass(hiddenClass) && !isVisible) {
				el.addClass(hiddenClass);
			}

			return this;
		},

		getElement: function () {
			return this.componentEl;
		},

		enterElement: function (parent, after) {
			var self = this;

			if(angular.isUndefined(parent)) {
				parent = angular.element(document.body);
			}

			this.emit('enterElementStart');

			return $animate.enter(this.getElement(), parent, after).then(function () {
				self.emit('enterElementSuccess');
			});
		},

		removeElement: function () {
			this.getElement().remove();
			this.componentEl = undefined;
			return this;
		},

		leaveElement: function () {
			var self = this;

			this.emit('leaveElementStart');

			return $animate.leave(this.getElement()).then(function () {
				self.emit('leaveElementSuccess');
			});
		},

		destroy: function () {
			this.removeElement();
		}
	});

	return MbComponent;
}

function MbComponentInterface (Helpers) {
	var MbComponentInterface = Helpers.createClass({
		show: Helpers.notImplemented('show'),
		hide: Helpers.notImplemented('hide'),
		toggle: Helpers.notImplemented('toggle'),
		setElement: Helpers.notImplemented('setElement'),
		getElement: Helpers.notImplemented('getElement'),
		setId: Helpers.notImplemented('setId'),<commit_msg>core/component: better documentation<commit_after>/**
 * @ngdoc object
 * @name MbComponent
 * @description
 * Create a new instance of MbComponent
 * @param {DOMElement} componentEl the component element, which will be showed and hidded
 * @param {string} id the component id
 * @param {object} options the component options
 */
function MbComponentFactory (MbComponentInterface, $animate) {
	var MbComponent = MbComponentInterface.extend({
		initialize: function (componentEl, id, options) {
			// defaults
			this.isVisible = false;

			if(angular.isObject(id)) {
				options = id;
				id = undefined;
				angular.extend(this, options);
			}

			if(angular.isDefined(componentEl)) {
				this.setElement(componentEl);
			}

			if(angular.isDefined(id)) {
				this.setId(id);
			}

			this.on('visibleStateChangeSuccess', function () {
				if(this.getVisibleState()) {
					this.emit('visible');
				} else {
					this.emit('notVisible');
				}
			});

			this.on('visibleStateChangeStart', function (visibleState) {
				if(visibleState) {
					this.emit('visibleChangeStart');
				} else {
					this.emit('notVisibleChangeStart');
				}
			});
		},

		/**
		 * @ngdoc method
		 * @name MbComponent#show
		 * @kind function
		 * @description Show the component
		 * @return {Promise} the animation callback promise
		 */
		show: function () {
			return this.setVisibleState(true);
		},

		/**
		 * @ngdoc method
		 * @name MbComponent#hide
		 * @kind function
		 * @description Hide the component
		 * @return {Promise} the animation callback promise
		 */
		hide: function () {
			return this.setVisibleState(false);
		},

		/**
		 * @ngdoc method
		 * @name MbComponent#toggle
		 * @kind function
		 * @description Toggle the component visible state
		 * @return {Promise} the animation callback promise
		 */
		toggle: function () {
			return this.setVisibleState(!this.getVisibleState());
		},

		getHiddenClass: function () {
			return 'mb-hidden';
		},

		getVisibleClass: function () {
			return 'mb-visible';
		},

		getVisibleState: function () {
			return !!this.isVisible;
		},

		/**
		 * @ngdoc method
		 * @name MbComponent#setVisibleState
		 * @kind function*
		 *
		 * @description Emit `visibleStateChangeStart` event before do anything,
		 * 		then add the visible class and/or remove the hidden, according
		 * 		to the setted visible state param and emit the final event
		 *		`visibleStateChangeSuccess` or `visibleStateChangeError` if we
		 *		got an error.
		 *
		 * @param {Boolean} visibleState the visible state to set
		 *
		 * @return {Promise} the animation callback promise
		 */
		setVisibleState: function (visibleState) {
			var self = this,
					el = this.getElement(),
					promises = [],
					addClass, // Class to add before animate
					removeClass, // Class to remove before animate
					hiddenClass = this.getHiddenClass(),
					visibleClass = this.getVisibleClass(),
					hiddenClassMethod = visibleState ? 'removeClass' : 'addClass';

			this.emit('visibleStateChangeStart', visibleState);

			addClass = visibleState ? visibleClass : hiddenClass;
			removeClass = visibleState ? hiddenClass : visibleClass;

			return $animate.setClass(el, addClass, removeClass).then(function () {
				self.isVisible = visibleState;
				self.emit('visibleStateChangeSuccess');
			}, function (err) {
				self.emit('visibleStateChangeError', err);
			});
		},

		setId: function (id) {
			if(angular.isDefined(this.getId())) {
				throw new Error('You cannot change a component.id more than once');
			}

			Object.defineProperty(this, 'id', {
				value: id,
				writable: false
			});

			return this;
		},

		getId: function () {
			return this.id;
		},

		setElement: function (componentEl) {
			var el = this.componentEl = componentEl,
					isVisible = this.getVisibleState(),
					hiddenClass = this.getHiddenClass();

			if(!el.hasClass(hiddenClass) && !isVisible) {
				el.addClass(hiddenClass);
			}

			return this;
		},

		getElement: function () {
			return this.componentEl;
		},

		enterElement: function (parent, after) {
			var self = this;

			if(angular.isUndefined(parent)) {
				parent = angular.element(document.body);
			}

			this.emit('enterElementStart');

			return $animate.enter(this.getElement(), parent, after).then(function () {
				self.emit('enterElementSuccess');
			});
		},

		removeElement: function () {
			this.getElement().remove();
			this.componentEl = undefined;
			return this;
		},

		leaveElement: function () {
			var self = this;

			this.emit('leaveElementStart');

			return $animate.leave(this.getElement()).then(function () {
				self.emit('leaveElementSuccess');
			});
		},

		/**
		 * @ngdoc method
		 * @name MbComponent#destroy
		 * @description
		 * Destroys the element permanently
		 */
		destroy: function () {
			this.removeElement();
		}
	});

	return MbComponent;
}

function MbComponentInterface (Helpers) {
	var MbComponentInterface = Helpers.createClass({
		show: Helpers.notImplemented('show'),
		hide: Helpers.notImplemented('hide'),
		toggle: Helpers.notImplemented('toggle'),
		setElement: Helpers.notImplemented('setElement'),
		getElement: Helpers.notImplemented('getElement'),
		setId: Helpers.notImplemented('setId'),
{'fraction_non_alphanumeric': 0.128308174867673, 'fraction_numerical': 0.0, 'mean_word_length': 3.4868073878627968, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7291552', 'n_tokens_mistral': 3657, 'n_tokens_neox': 2910, 'n_words': 714}