Skip to content

Instantly share code, notes, and snippets.

@wasbazi
Last active January 4, 2016 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wasbazi/8622044 to your computer and use it in GitHub Desktop.
Save wasbazi/8622044 to your computer and use it in GitHub Desktop.
// env.js
_documentSetter: function(document){
this.document = document;
// if this is a document model it will have the watch function,
// if not it will throw an error and everything dies, but I doubt
// a non doc-model will be passed
if (this._constrainedProductsWatch) {
this._constrainedProductsWatch.remove();
}
this._constrainedProductsWatch = this.document.watch('constrainedProducts', lang.hitch(this, function(name, oldValue, newValue){
if (newValue.length) {
topic.publish('showCQM');
}
}));
}
/// builder.js
topic.subscribe('constrainedProducts', lang.hitch(this, function(){
if (this._constrainedProductsTimeout) {
clearTimeout(this._constrainedProductsTimeout);
}
this._constrainedProductsTimeout = setTimeout(lang.hitch(this, function(){
this._constrainedProductsTimeout = null;
this.CQM.show();
}), 300);
}));
/// models/document/PageItem.js
_atsInfoSetter: function(atsInfo){
this.atsInfo = atsInfo;
if (atsInfo.availableQuantity < this.quantity) {
// something like this
topic.publish('tooMuchQty', this.stockItem);
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment