MCPcopy
hub / github.com/tc39/proposal-observable / from

Method from

src/Observable.js:265–304  ·  view source on GitHub ↗
(x)

Source from the content-addressed store, hash-verified

263 // == Derived ==
264
265 static from(x) {
266
267 let C = typeof this === "function" ? this : Observable;
268
269 if (x == null)
270 throw new TypeError(x + " is not an object");
271
272 let method = getMethod(x, Symbol.observable);
273
274 if (method) {
275
276 let observable = method.call(x);
277
278 if (Object(observable) !== observable)
279 throw new TypeError(observable + " is not an object");
280
281 if (observable.constructor === C)
282 return observable;
283
284 return new C(observer => observable.subscribe(observer));
285 }
286
287 method = getMethod(x, Symbol.iterator);
288
289 if (!method)
290 throw new TypeError(x + " is not observable");
291
292 return new C(observer => {
293
294 for (let item of method.call(x)) {
295
296 observer.next(item);
297
298 if (observer.closed)
299 return;
300 }
301
302 observer.complete();
303 });
304 }
305
306 static of(...items) {
307

Calls 2

getMethodFunction · 0.85
subscribeMethod · 0.80

Tested by

no test coverage detected