1////////////////////////////////////////////////////////////////////////// 2// // 3// This is a generated file. You can view the original // 4// source in your browser if your browser supports source maps. // 5// Source maps are supported by all recent versions of Chrome, Safari, // 6// and Firefox, and by Internet Explorer 11. // 7// // 8////////////////////////////////////////////////////////////////////////// 9 10 11(function () { 12 13/* Imports */ 14var Meteor = Package.meteor.Meteor; 15var global = Package.meteor.global; 16var meteorEnv = Package.meteor.meteorEnv; 17var Tracker = Package.tracker.Tracker; 18var Deps = Package.tracker.Deps; 19var ReactiveVar = Package['reactive-var'].ReactiveVar; 20var _ = Package.underscore._; 21var meteorInstall = Package.modules.meteorInstall; 22var meteorBabelHelpers = Package.modules.meteorBabelHelpers; 23var Promise = Package.promise.Promise; 24var Symbol = Package['ecmascript-runtime-client'].Symbol; 25var Map = Package['ecmascript-runtime-client'].Map; 26var Set = Package['ecmascript-runtime-client'].Set; 27 28/* Package-scope variables */ 29var ComputedField; 30 31var require = meteorInstall({"node_modules":{"meteor":{"peerlibrary:computed-field":{
31"lib.js":function module(require,exports,module){ 32 33///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34// // 35// packages/peerlibrary_computed-field/lib.js // 36// // 37///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 38 // 39module.export({ 40 ComputedField: function () { 41 return ComputedField; 42 } 43}); 44 45var ComputedField = function () { 46 function ComputedField(func, equalsFunc, dontStop) { 47 // To support passing boolean as the second argument. 48 if (_.isBoolean(equalsFunc)) { 49 dontStop = equalsFunc; 50 equalsFunc = null; 51 } 52 53 var handle = null; 54 var lastValue = null; // TODO: Provide an option to prevent using view's autorun. 55 // One can wrap code with Blaze._withCurrentView(null, code) to prevent using view's autorun for now. 56 57 var autorun; 58 var currentView = Package.blaze && Package.blaze.Blaze && Package.blaze.Blaze.currentView; 59 60 if (currentView) { 61 if (currentView._isInRender) { 62 // Inside render we cannot use currentView.autorun directly, so we use our own version of it. 63 // This allows computed fields to be created inside Blaze template helpers, which are called 64 // the first time inside render. While currentView.autorun is disallowed inside render because 65 // autorun would be recreated for reach re-render, this is exactly what computed field does 66 // anyway so it is OK for use to use autorun in this way. 67 autorun = function (f) {
68 var templateInstanceFunc = Package.blaze.Blaze.Template._currentTemplateInstanceFunc; 69 var comp = Tracker.autorun(function (c) { 70 Package.blaze.Blaze._withCurrentView(currentView, function () { 71 Package.blaze.Blaze.Template._withTemplateInstanceFunc(templateInstanceFunc, function () { 72 f.call(currentView, c); 73 }); 74 }); 75 }); 76 77 var stopComputation = function () { 78 comp.stop(); 79 }; 80 81 currentView.onViewDestroyed(stopComputation); 82 comp.onStop(function () { 83 currentView.removeViewDestroyedListener(stopComputation); 84 }); 85 return comp; 86 }; 87 } else { 88 autorun = function (f) { 89 return currentView.autorun(f); 90 }; 91 } 92 } else { 93 autorun = Tracker.autorun; 94 } 95 96 var startAutorun = function () { 97 handle = autorun(function (computation) { 98 var value = func(); 99 100 if (!lastValue) { 101 lastValue = new ReactiveVar(value, equalsFunc); 102 } else { 103 lastValue.set(value); 104 } 105 106 if (!dontStop) { 107 Tracker.afterFlush(function () { 108 // If there are no dependents anymore, stop the autorun. We will run 109 // it again in the getter's flush call if needed. 110 if (!lastValue.dep.hasDependents()) { 111 getter.stop(); 112 } 113 }); 114 } 115 }); // If something stops our autorun from the outside, we want to know that and update internal state accordingly. 116 // This means that if computed field was created inside an autorun, and that autorun is invali
116ded our autorun is 117 // stopped. But then computed field might be still around and it might be asked again for the value. We want to 118 // restart our autorun in that case. Instead of trying to recompute the stopped autorun. 119 120 if (handle.onStop) { 121 handle.onStop(function () { 122 handle = null; 123 }); 124 } else { 125 // XXX COMPAT WITH METEOR 1.1.0 126 var originalStop = handle.stop; 127 128 handle.stop = function () { 129 if (handle) { 130 originalStop.call(handle); 131 } 132 133 handle = null; 134 }; 135 } 136 }; 137 138 startAutorun(); 139 140 var getter = function () { 141 // We always flush so that you get the most recent value. This is a noop if autorun was not invalidated. 142 getter.flush(); 143 return lastValue.get(); 144 }; // We mingle the prototype so that getter instanceof ComputedField is true. 145 146 147 if (Object.setPrototypeOf) { 148 Object.setPrototypeOf(getter, this.constructor.prototype); 149 } else { 150 getter.__proto__ = this.constructor.prototype; 151 } 152 153 getter.toString = function () { 154 return "ComputedField{" + this() + "}"; 155 }; 156 157 getter.apply = function () { 158 return getter(); 159 }; 160 161 getter.call = function () { 162 return getter(); 163 }; // If this autorun is nested in the outside autorun it gets stopped automatically when the outside autorun gets 164 // invalidated, so no need to call destroy. But otherwise you should call destroy when the field is not needed anymore. 165 166 167 getter.stop = function () { 168 if (handle != null) { 169 handle.stop(); 170 } 171 172 return handle = null; 173 }; // For tests. 174 175 176 getter._isRunning = function () { 177 return !!handle; 178 }; // Sometimes you want to force recomputation of the new value before the global Tracker flush is done. 179 // This is a noop if autorun was not invalidated. 180 181 182 getter.flush = function () { 183 Tracker.nonreactive(function () { 184 if (handle) { 185 handle.flush(); 186 } else { 187 // If there is no autorun, create it now. This will do initial recomputation as well. If there 188 // will be no dependents after the global flush, autorun will stop (again). 189 startAutorun(); 190 } 191 }); 192 }; 193 194 return getter; 195 } 196 197 return ComputedField; 198}(); 199///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 200 201}
201}}}},{ 202 "extensions": [ 203 ".js", 204 ".json", 205 ".css" 206 ] 207}); 208 209var exports = require("/node_modules/meteor/peerlibrary:computed-field/lib.js"); 210 211/* Exports */ 212Package._define("peerlibrary:computed-field", exports, { 213 ComputedField: ComputedField 214}); 215 216})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.