Download pool/shard003/JavaScript/0019050_scope.js from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard003/JavaScript/0019050_scope.js
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard003/JavaScript/0019050_scope.js
-
curl -L -o 0019050_scope.js https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard003/JavaScript/0019050_scope.js
1.8 kB
| var _ = require('lodash'); | |
| var Scope = function() { | |
| this.$$watchers = []; | |
| this.$$asyncQueue = []; | |
| } | |
| Scope.prototype.$watch = function (watchFn, listenerFn, valueEq) { | |
| var watcher = { | |
| watchFn: watchFn, | |
| listenerFn: listenerFn || function() {}, | |
| valueEq: !!valueEq | |
| }; | |
| this.$$watchers.push(watcher); | |
| }; | |
| Scope.prototype.$$digestOnce = function () { | |
| var self = this; | |
| var dirty; | |
| _.forEach(this.$$watchers, function(watch) { | |
| var newValue = watch.watchFn(self); | |
| var oldValue = watch.last; | |
| if (!self.$$areEquals(newValue, oldValue, watch.valueEq)) { | |
| watch.listenerFn(newValue, oldValue, self); | |
| dirty = true; | |
| watch.last = (watch.valueEq ? _.cloneDeep(newValue) : newValue); | |
| } | |
| }); | |
| return dirty; | |
| }; | |
| Scope.prototype.$digest = function() { | |
| var ttl = 10; | |
| var dirty; | |
| do { | |
| while (this.$$asyncQueue.length) { | |
| var asyncTask = this.$$asyncQueue.shift(); | |
| this.$eval(asyncTask.expression); | |
| } | |
| dirty = this.$$digestOnce(); | |
| if (dirty && !(ttl--)) { | |
| throw "10 digest iterations reached"; | |
| } | |
| } while (dirty); | |
| }; | |
| Scope.prototype.$$areEquals = function (newValue, oldValue, valueEq) { | |
| if (valueEq) { | |
| return _.isEqual(newValue, oldValue); | |
| } else { | |
| return newValue === oldValue || (typeof newValue == 'number' && typeof oldValue == 'number' && isNaN(newValue) && isNaN(oldValue)); | |
| } | |
| }; | |
| Scope.prototype.$eval = function(expr, locals) { | |
| return expr(this, locals); | |
| }; | |
| Scope.prototype.$apply = function(expr) { | |
| try { | |
| return this.$eval(expr); | |
| } finally { | |
| this.$digest(); | |
| } | |
| }; | |
| Scope.prototype.$evalAsync = function (expr) { | |
| this.$$asyncQueue.push({scope:this, expression: expr}); | |
| }; | |
| module.exports = Scope; | |