Skip to content

Instantly share code, notes, and snippets.

//Basic Types: boolean, string, arrays, number,
// null, undefined, void, object, never, Symbol
var grettings: string = "Hola esto es un string";
grettings = {attendets: "gracias por venir"}; //error
//capturar comportamientos inesperados
const sumWeird = {attendets: "Hola"} + ["como estan"]; //error
//Type inference
const Ix = require('ix');
async function* arrGen() {
yield 1;
yield 2;
yield 4;
}
const results = Ix.AsyncIterable.from(arrGen())
.filter(x => x % 2 === 0)
//importar la librería IxJS
const Ix = require('ix');
//Crea la fuente de datos con una función async generator
async function* arrGen() {
yield 1;
yield 2;
yield 4;
}
//Crea un objeto que IxJS entienda; Async Iterable.
//se crea la función generadora con la anotación "function*"
const arr = function* arrGen(){
yield 1 // yield detiene la función, devuelve 1 y cuándo se ejecute de nuevo next()
// continuá en la siguiente linea de código la #5
yield 2 // yield detiene la función, devuelve 2 y cuándo se ejecute de nuevo next()
// continuá en la siguiente linea de código la #7
yield 4 // yield detiene la función, devuelve 2 y cuándo se ejecute de nuevo next()
// devulve undefined y la propiedad done igual a true
}
const arr = [1,2,4][Symbol.iterator]()
console.log('Next in array_as_iterable 1', arr.next())
// Next in array_as_iterable 1
// {value: 1, done: false }
console.log('Next in array_as_iterable 2', arr.next())
// Next in array_as_iterable 2
// {value: 2, done: false }
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<h1 id="title">Hola</h1>
@ltciro
ltciro / Observable_in_vanillaJS.md
Last active January 20, 2023 11:16
simulate pattern observable in vanilla JS

Rxjs

const next = (message)=> console.log("First observer message: " + message);
const error = (error) => console.log("Second observer error: " + error);
const complete = () => console.log("complete");

const next1 = (message)=> console.log("First observer message 1: " + message);
const error1 = (error) => console.log("Second observer error 1: " + error);
const complete1 = () => console.log("complete 1");