[Most.js] Create Streams From Single Values With Most.js

weixin_30639719發表於2020-04-05

Most provides many means for creating streams, the simplest of which is the offunction. In this lesson, we demonstrate the use of of to lift a single value into a stream. We also show off the just alias of of, as well as, a common method for currying a function.

 

Use CDN:

most.of('anything')

console.log(stream) // { source: { value: 'anything' } }

 

Use require:

const { just , of} = most

const log =
  label => value => logger(label, value);

most.of('anything')
  .observe(log('string'))

just('anything')
  .observe(log('string'))

just(23)
  .observe(log('number'))

// Bonus Bits
// Lift all the things
just(true)
  .observe(log('boolean'))

just({ a: 1, b: 2 })
  .observe(log('object'))

just([ 1, 2, 3])
  .observe(log('array'))

just(x => x)
  .observe(log('function'))

just(undefined)
  .observe(log('undefined'))

/*
string:
'anything'
string:
'anything'
number:
23
boolean:
true
object:
{ a: 1, b: 2 }
array:
[ 1, 2, 3 ]
function:
Function
undefined:
undefined
*/

 

轉載於:https://www.cnblogs.com/Answer1215/p/6277533.html

相關文章