123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- define(['underscore'], function (_) {
- return function () {
- function VisRenderState() {
- _classCallCheck(this, VisRenderState);
-
- this._currentContext = {};
-
- this._renderContextPool = {};
-
- this.firstRenderComplete = false;
- this.lastSizeRendered = null;
- this._steps = [];
- }
- VisRenderState.prototype.remove = function remove() {
- this.resetRenderState();
- };
- VisRenderState.prototype.initCurrentContext = function initCurrentContext(stepName) {
- if (!this._currentContext.hasOwnProperty(this._stepToStepContext(stepName))) {
- this._steps.push(stepName);
- this._currentContext[this._stepToStepContext(stepName)] = null;
- }
- };
-
- VisRenderState.prototype.getCurrentContext = function getCurrentContext(stepName) {
- return this._currentContext[this._stepToStepContext(stepName)];
- };
-
-
- VisRenderState.prototype.getCurrentContextData = function getCurrentContextData(stepName) {
- return this._currentContext[this._stepToStepContext(stepName)] ? this._currentContext[this._stepToStepContext(stepName)][stepName] : null;
- };
-
- VisRenderState.prototype.addRenderContext = function addRenderContext(options) {
- if (_.isUndefined(options) || _.isUndefined(options.renderId)) {
- throw new Error('cannot define a render context: missing renderId');
- }
- var renderContext = {
- id: options.renderId
- };
- _.each(this._steps, function (step) {
- renderContext[step] = null;
- });
- if (_.keys(options).length > 1) {
- renderContext.extraInfo = options.extraInfo;
- if (this._currentContext.dataContext && options.extraInfo && options.extraInfo.sender === 'realtimeRefresh') {
-
-
- renderContext.previousData = this._currentContext.dataContext.data;
- }
- }
- renderContext.resizing = options && options.resizing ? true : false;
- this._renderContextPool[renderContext.id] = renderContext;
- if (_.keys(options).length > 1) {
- if (options.refresh && options.refresh.data && !this.readyToLoadData()) {
- options.refreshAll = true;
- }
- if (options.refresh) {
- options.refresh.render = true;
- } else {
-
- options.refresh = {
- render: true
- };
- }
- renderContext.refresh = options.refresh;
- renderContext.refreshAll = options.refreshAll;
- if (options.refreshAll) {
-
- this.reloadAllRenderSteps();
- _.each(_.keys(this._currentContext), function (key) {
- this._currentContext[key] = renderContext;
- }.bind(this));
- } else if (options.refresh) {
-
- _.each(_.keys(options.refresh), function (stepName) {
- this._currentContext[this._stepToStepContext(stepName)] = renderContext;
- }.bind(this));
-
- if (!this._currentContext.visViewContext) {
- this._currentContext.visViewContext = renderContext;
- }
- }
- }
- return renderContext;
- };
-
- VisRenderState.prototype.readyToLoadData = function readyToLoadData() {
- return !!(this.getCurrentContextData('visView') && this.getCurrentContextData('visControl'));
- };
-
- VisRenderState.prototype.readyToRender = function readyToRender() {
- return !!(this.getCurrentContextData('visView') && this.getCurrentContextData('visControl') && this.getCurrentContextData('data'));
- };
-
- VisRenderState.prototype.resetRenderState = function resetRenderState() {
- this.lastSizeRendered = null;
- this._clearCurrentContext();
- this.cleanRenderContextPool( true);
- };
-
- VisRenderState.prototype._renderContextUnused = function _renderContextUnused(thisRenderContext) {
- var thisRenderContextFound = _.find(_.keys(this._currentContext), function (step) {
- return this._currentContext[step] === thisRenderContext;
- }.bind(this));
-
- if (thisRenderContextFound) {
- return false;
- }
-
- return thisRenderContext.renderComplete ? true : false;
- };
-
- VisRenderState.prototype.cleanRenderContextPool = function cleanRenderContextPool(removeAll) {
- _.each(_.keys(this._renderContextPool), function (key) {
- var renderContext = this._renderContextPool[key];
- if (removeAll || this._renderContextUnused(renderContext)) {
- delete this._renderContextPool[key];
- }
- }.bind(this));
- };
-
- VisRenderState.prototype._clearCurrentContext = function _clearCurrentContext() {
- if (this.getCurrentContextData('visView')) {
- this.getCurrentContextData('visView').remove();
- }
- _.each(_.keys(this._currentContext), function (key) {
- this._currentContext[key] = null;
- }.bind(this));
- };
-
- VisRenderState.prototype.reloadAllRenderSteps = function reloadAllRenderSteps() {
- if (this.getCurrentContextData('visView')) {
- this.getCurrentContextData('visView').remove( false);
- }
- _.each(_.keys(this._currentContext), function (stepContext) {
-
-
-
- var step = this._stepContextToStep(stepContext);
- if (this._currentContext[stepContext] && this._currentContext[stepContext][step]) {
- this._currentContext[stepContext][step] = null;
- }
- }.bind(this));
- };
-
- VisRenderState.prototype.getFullRenderContext = function getFullRenderContext() {
- var fullRenderContext = {};
- for (var stepContext in this._currentContext) {
-
- var step = this._stepContextToStep(stepContext);
- fullRenderContext[step] = this._currentContext[stepContext] && this._currentContext[stepContext][step] || null;
- }
- return fullRenderContext;
- };
-
-
- VisRenderState.prototype._stepToStepContext = function _stepToStepContext(stepName) {
- return stepName + 'Context';
- };
-
-
- VisRenderState.prototype._stepContextToStep = function _stepContextToStep(contextName) {
- return contextName.substring(0, contextName.length - 7);
- };
- return VisRenderState;
- }();
- });
|