How to use the ko.isObservable function in ko

To help you get started, we’ve selected a few ko examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jaystack / jaydata / src / JayDataModules / knockout.js View on Github external
$data.Queryable.prototype.toArray = function (onResult_items, transaction) {
            if (ko.isObservable(onResult_items)) {
                if (typeof onResult_items.push !== 'undefined') {
                    var callBack = $data.PromiseHandlerBase.createCallbackSettings();

                    return this.toArray(function (results, tran) {
                        onResult_items(results.map(function(it){ return it instanceof $data.Entity ? it.asKoObservable() : it; }));
                    }, transaction);
                } else {
                    return queryableToArray.call(this, function (result, tran) { onResult_items(result); }, transaction);
                }
            } else {
                return queryableToArray.call(this, onResult_items, transaction);
            }
        }
        /* Observable entities End*/
github BladeRunnerJS / brjs / brjs-sdk / workspace / sdk / libs / javascript / br-knockout / src / br / knockout / workbench / KnockoutModelTree.js View on Github external
KnockoutModelTree.prototype._buildNodes = function( treeNode, viewModel, expandNode ) {
  for (var key in viewModel) {

    if( isPrivateVariable( key ) ) {
      continue;
    }

    // TODO: refactor like-crazy!
    var item = viewModel[ key ];
    var treeChildNode;
    var label;
    var value;
    if ( ko.isObservable( item ) ) {
      this._addObservableToTree( treeNode, key, item, expandNode );
    }
    else if( typeof item === 'object' && hasObservables( item ) ) {
      treeChildNode = new Ext.tree.TreeNode( { text : key, expanded: expandNode } );
      treeNode.appendChild( treeChildNode );
      this._buildNodes( treeChildNode, item, true );
    }
    else if( typeof item !== 'function' ) {
      label = key;
      value = viewModel[ key ];
      if( value !== undefined ) {
        label += ':' + getSafeJsonValue( value );
      }
      treeChildNode = new Ext.tree.TreeNode( { text : label, expanded: expandNode } );
      treeNode.appendChild( treeChildNode );
    }
github jaystack / jaydata / src / JayDataModules / knockout.js View on Github external
var deepReconvert = function deepReconvert(value) {
        if (Array.isArray(value)) return value.map(deepReconvert);
        if (ko.isObservable(value)){
            value = value.peek();
            return deepReconvert(value);
        }
        if (value && typeof value.getEntity == "function"){
            value = value.getEntity();
        }
        return value;
    };
github BladeRunnerJS / brjs / brjs-sdk / workspace / sdk / libs / javascript / br-knockout / src / br / knockout / workbench / KnockoutJsTreeModelFactory.js View on Github external
KnockoutJsTreeModelFactory._hasObservables = function(object) {
	var isObservable = false;
	
	for(var key in object) {
		isObservable = ko.isObservable(object[key]);
		
		if(isObservable) {
			break;
		}
	}
	
	return isObservable;
};
github BladeRunnerJS / brjs / brjs-sdk / workspace / sdk / libs / javascript / br-knockout / src / br / knockout / workbench / KnockoutJsTreeModelFactory.js View on Github external
KnockoutJsTreeModelFactory._processViewModel = function(viewModel, treeModel, treeModelItems) {
	for(var itemName in viewModel) {
		if(!this._isPrivate(itemName)) {
			var item = viewModel[itemName];
			
			if(ko.isObservable(item)) {
				var treeItem = {id: "node_id_" + this._uniqueID++ , text:itemName + ": " + item()};
				item.subscribe(this._createNewTreeItemSubscriber(treeModel, itemName, treeItem));
				treeModelItems.push(treeItem);
			}
			else if((typeof item === 'object') && this._hasObservables(item)) {
				var childTreeModel = {text:itemName, state: {opened: true}, children:[]};
				
				treeModelItems.push(childTreeModel);
				this._processViewModel(item, treeModel, childTreeModel.children);
			}
			else if((typeof item !== 'function')) {
				treeModelItems.push({text:itemName + ": " + item});
			}
		}
	}
};
github jaystack / jaydata / src / JayDataModules / knockout.js View on Github external
function checkObservableValue(expression, context) {
            if (expression instanceof $data.Expressions.ConstantExpression && ko.isObservable(expression.value)) {
                context.some(function (item) {
                    if (item.observable === expression.value) {
                        item.skipExecute = true;
                    }
                });
                context.push({
                    observable: expression.value,
                    skipExecute: false
                });
                var observableValue = expression.value();
                return Container.createConstantExpression(observableValue, Container.getTypeName(observableValue), expression.name + '$Observable');
            }
            return expression;
        }
github BladeRunnerJS / brjs / brjs-sdk / workspace / sdk / libs / javascript / br-knockout / src / br / knockout / workbench / KnockoutModelTree.js View on Github external
function isObservableArray( obj ) {
  return ( ko.isObservable(obj) && obj.hasOwnProperty('removeAll')  );
}
github BladeRunnerJS / brjs / brjs-sdk / workspace / sdk / libs / javascript / br-knockout / src / br / knockout / workbench / KnockoutModelTree.js View on Github external
function hasObservables( obj ) {
  var isObservable = false;
  for( var x in obj ) {
    isObservable = ko.isObservable( obj[ x ] );
    if( isObservable ) {
      break;
    }
  }
  return isObservable;
}
github BladeRunnerJS / brjs / brjs-sdk / workspace / sdk / libs / javascript / br-knockout / src / br / knockout / workbench / KnockoutJsTreeModelFactory.js View on Github external
KnockoutJsTreeModelFactory._processViewModel = function(viewModel, treeModelItems) {
	for(var itemName in viewModel) {
		if(!this._isPrivate(itemName)) {
			var item = viewModel[itemName];
			
			if(ko.isObservable(item)) {
				treeModelItems.push({text:itemName + ": " + item()});
			}
			else if((typeof item === 'object') && this._hasObservables(item)) {
				var childTreeModel = {text:itemName, state: {opened: true}, children:[]};
				
				treeModelItems.push(childTreeModel);
				this._processViewModel(item, childTreeModel.children);
			}
			else if((typeof item !== 'function')) {
				treeModelItems.push({text:itemName + ": " + item});
			}
		}
	}
};