Skip to content

Instantly share code, notes, and snippets.

View dinony's full-sized avatar

Onur Doğangönül dinony

View GitHub Profile
@dinony
dinony / index.js
Last active June 15, 2017 02:09
Multicast Observables: Subjects
// https://gist.github.com/dinony/60332358d25fd18d561395e0b8bf807c
// In the above Gist, we've discussed the constraints of unicast Observables,
// when it comes to sharing a costly resource.
//
// Here, you'll see how Subjects can be used to avoid this problematic scenario.
import {Obervable} from 'rxjs/Observable';
import {Subject} from 'rxjs/Subject';
// Again, we have our default Observable, which manages some costly resource.
const obs = new Observable(observer => {
@dinony
dinony / index.js
Last active June 15, 2017 02:10
Unicast Observables
// Here, we create a default Observable, which manages some costly resource
// or performs some heavy computation (denoted by the crying emoji) to push
// values to it's Observers. Now imagine, this could be a http call,
// database connection or socket connection, etc ...
//
// Each subscribed Observer gets an independent execution context.
// If we had only a single subscribe call - everything would be fine.
// We'd have just a single execution, and the costly resource is allocated
// just one time. So far, so good.
//
@dinony
dinony / app.component.ts
Last active May 6, 2017 13:53
Angular 4.1.0 animations: Basic 2 state animation with transition
import {Component} from '@angular/core';
import {myAnim} from './myAnim';
@Component({
selector: 'app-shell',
styles: [`
.container {
display: flex;
justify-content: center;
@dinony
dinony / my-comp.component.ts
Last active May 6, 2017 09:14
Angular 4.1.0 animations: Basic component setup and animation methods
import {Component} from '@angular/core';
import {trigger, state, style, animate, transition} from '@angular/animations';
@Component({
selector: 'my-comp',
styles: [], // <-- Add your styles here
animations: [], // <-- Add your animation meta data here
template: '' // <-- Define your template here
})
@dinony
dinony / app.module.ts
Created May 6, 2017 08:26
Angular 4.1.0 animations: Import required modules
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {AppComponent} from './app.component';
@NgModule({
bootstrap: [AppComponent],
declarations: [AppComponent],
imports: [BrowserModule, BrowserAnimationsModule]
@dinony
dinony / systemjs.config.js
Last active June 1, 2017 10:26
Angular 4.2.0 animations: Minimal SystemJS setup with typescript plugin
System.config({
transpiler: 'ts',
meta: {
'typescript': {
"exports": "ts"
}
},
paths: {
'npm:': 'https://unpkg.com/'
},