A case study of 2 TC39 proposals

Does everyone here know in general what the TC39 Committee is?



Stage 0: strawman
Stage 1: committee committed to solving problem
Stage 2: draft spec stage
Stage 3: implementations
Stage 4: final spec ready to merge
Stages

Observables
(aka RxJs, Reactive JS )

What is an observable and why has it been proposed as part of the Javascript ECMA-262 standard?
An observable is a constructor that takes an observer and calls that observer with a stream of event(s) when the event(s) occur.

import fs from 'fs/promises'
import { Observable } from 'rxjs'
const myFunc = async function (observer) {
const result = await fs.readFile('package.json', 'utf8')
observer.next(result)
}
const observer = x => console.log(x)
const myObs = new Observable(myFunc)
myObs.subscribe(observer)
Single Shot Event

import fs from 'fs/promises'
import { Observable } from 'rxjs'
import { map, distinctUntilChanged } from 'rxjs/operators'
const myFunc = async function (observer) {
const handler = async () => {
const result = await fs.readFile('package.json', 'utf8')
observer.next(result)
}
setInterval(handler, 1000)
}
const observer = x => {
console.log(Array(100).join('-'))
console.log(' my observer')
console.log(Array(100).join('-'))
console.log(x)
}
const myObs = new Observable(myFunc)
const myMappedObs = myObs.pipe(map(pkg => parseInt(JSON.parse(pkg).version)))
const distinctObs = myMappedObs.pipe(distinctUntilChanged())
distinctObs.subscribe(observer)
Stream of changed events

interfaceint Observable {
constructor(subscriber : SubscriberFunction);
// Subscribes to the sequence with an observer
subscribe(observer : Observer) : Subscription;
// Subscribes to the sequence with callbacks
subscribe(next : Function,
error? : Function,
complete? : Function) : Subscription;
}
interface Subscription {
// Cancels the subscription
unsubscribe() : void;
}Interfaces

The observables proposal was started in May 2015, it is complex, and uncharacteristic
of the process.

>1000 Days so far in the process
Array lastItem Proposal
// wouldn't this be nice
const myArray = [1, 2, 3];
console.log(myArray.lastItem);
// instead of
console.log(myArray[myArray.length-1])
How did we manage to invent a language without an operator for the last element in an array?
This happened because it has happened before.
Yes even my dearest BFF C++ missed this
#include <iostream>
#include <vector>
int main ()
{
// constructors used in the same order as described above:
std::vector<int> first; // empty vector of ints
std::vector<int> second (4,100); // four ints with value 100
std::vector<int> third (second.begin(),second.end()); // iterating through second
std::vector<int> fourth (third); // a copy of third
// the iterator constructor can also be used to construct from arrays:
int myints[] = {16,2,77,29};
std::vector<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );
std::cout << "The contents of fifth are:";
for (std::vector<int>::iterator it = fifth.begin(); it != fifth.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}C++ has libraries that fix this (STL)
The Java language was similar to C++ but it too had collections that had first and last items
Days since array lastItem feature was proposed
170, it is being pushed hard and is less complex than observables
Some features take longer than others!
Even simple proposals take up to 8 months to go through the process.
some quotes from a committee member
“It takes a long time, but we want to make sure we do it right”
“A lot of the work is soliciting feedback from the community”
So if you think you would like a lastItem operation on arrays please go and star the following link https://github.com/keithamus/proposal-array-last
because it is likely that we can grow the Javascript language incrementally.
(if you are in this room you should be taking an interest )
Observables demos at https://github.com/ghinks/bootcampers-talk-august-2018.git
other TC 39 proposals demonstrated at https://github.com/ghinks/tc-39-examples.git
Pop quiz






TC39 Case Study of 2 proposals
By Glenn Hinks
TC39 Case Study of 2 proposals
A case study of the array last property and the observables proposal
- 279