UNPKG

catreact

Version:

Catavolt Core React Components

63 lines (62 loc) 1.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Created by rburson on 12/23/15. */ var React = require("react"); var catreact_core_1 = require("./catreact-core"); var catavolt_sdk_1 = require("catavolt-sdk"); /** * Render an sdk {Workbench} */ exports.CvWorkbench = React.createClass({ mixins: [catreact_core_1.CvBaseMixin], appWinDef: function () { return this.props.appWinDef || this.firstInScope(catavolt_sdk_1.AppWinDef); }, getDefaultProps: function () { return { appWinDef: null, workbenchId: null, workbench: null }; }, getChildContext: function () { var ctx = this.getDefaultChildContext(); ctx.cvContext.scopeCtx.scopeObj = this.workbench(); return ctx; }, render: function () { var workbench = this.workbench(); if (workbench) { if (this.props.renderer) { return this.props.renderer(this.getChildContext().cvContext); } else if (React.Children.count(this.props.children) > 0) { return this.props.children; } else { return null; } } else { return null; } }, workbench: function () { var _this = this; if (this.props.workbench) { return this.props.workbench; } else { var appWinDef = this.appWinDef(); var workbench_1 = null; appWinDef.workbenches.some(function (wb) { if (wb.workbenchId == _this.props.workbenchId) { workbench_1 = wb; return true; } else { return false; } }); return workbench_1; } } });