of

BlackStone·2022년 12월 21일
0

Observable

What is of() ?

of() turns any plain value into an observable.
It can be one than one types of value and any number of values.

import { of } from 'rxjs'

const numbers = [ 1, 2, 3, 4, 5]
const numberObservable = of(numbers)
numberObservable.subscribe(number => console.log(number))
// outputs...
// 1
// 2
// 3
// 4
// 5


const mixSource = of({ age: 14 }, [ 1 ,2, 3 ], function hello() { return 'Hello'})
mixSource.subscribe(source => console.log(source))
// outpus...
// { age : 14 }
// [ 1, 2, 3]
// function hello() { return 'Hello' }

As you can see in the example that it doesnt run any function that is fed as a source but just spits them out from the subscription.

profile
Frontend Developer in North !

0개의 댓글