UNPKG

catreact

Version:

Catavolt Core React Components

55 lines (54 loc) 1.65 kB
/** * Created by rburson on 4/14/16. */ "use strict"; var React = require('react'); var catreact_core_1 = require('../core/catreact-core'); /* *************************************************** * Provide Logout Support to other components *************************************************** */ exports.CvLogout = React.createClass({ mixins: [catreact_core_1.CvBaseMixin], getChildContext: function () { return this.getDefaultChildContext(); }, getDefaultProps: function () { return { renderer: null, logoutListeners: [] }; }, render: function () { if (this.props.renderer) { return this.props.renderer(this.getChildContext().cvContext, this._getCallbackObject()); } else { return null; } }, _getCallbackObject: function () { var _this = this; return { isLoggedIn: function () { return _this.catavolt().isLoggedIn; }, logout: function () { _this._postLogout(_this.catavolt().logout()); } }; }, _postLogout: function (logoutResult) { var _this = this; logoutResult.onComplete(function (result) { var eventRegistry = _this.eventRegistry(); var event = { type: catreact_core_1.CvEventType.LOGOUT, eventObj: null }; eventRegistry.publish(event, false); _this.props.logoutListeners.forEach(function (listener) { listener(event); }); eventRegistry.clearAll(); }); } });