Skip to content

Commit

Permalink
Add "Operators - Creation - defer" example.
Browse files Browse the repository at this point in the history
  • Loading branch information
rickbeerendonk committed Feb 15, 2020
1 parent 1aae28a commit d301057
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions 02 - Operators - TODO/Creation - TODO/defer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*! European Union Public License version 1.2 !*/
/*! Copyright © 2020 Rick Beerendonk !*/

const { defer, from } = require('../../node_modules/rxjs');

const obs1 = from([1, 3, 5]);
const obs2 = from([10, 20, 30]);

let condition;

const obs3 = defer(() => (condition ? obs1 : obs2));

// obs3: condition = false

condition = false;

obs3.subscribe({
next: val => console.log(val),
complete: () => console.log('Complete!')
});

// obs3: condition = true

condition = true;

obs3.subscribe({
next: val => console.log(val),
complete: () => console.log('Complete!')
});

// 10
// 20
// 30
// Complete!
// 1
// 3
// 5
// Complete!

0 comments on commit d301057

Please sign in to comment.