Skip to content

Instantly share code, notes, and snippets.

View kosich's full-sized avatar

Kostia P kosich

View GitHub Profile
@kosich
kosich / app.js
Created March 14, 2015 18:53
ng html5 dnd example
'use strict';
var DATA_TYPE_ATTR = 'text/html';
// a hack to include `dataTransfer` to $ events
jQuery.event.props.push('dataTransfer');
angular.module( 'app', [] )
.controller ( 'main', function( $scope, dndBuffer ){

this approach is based not on blocking some square on the screen, but rather blocking events from other device (after touch interaction mouse events are blocked for some period and vice versa)

note: its a draft for angular-hammer use, so one would need to modify it a little to use with native elements ( atm it accepts jQuery element and addresses dom via element[0] )

@kosich
kosich / gist:375da99403c76bc75bbd
Last active August 29, 2015 14:18
Well-Known Symbols: array item getter/setter

Currently we can imitate Arrays only with objects, where we would refer to a value at some position via referring to objects property ( with integer index being converted to a string )

var arr = {
  "0" : "zero",
  "1" : "one" 
};

arr[ 1 ];

But we wouldn't get all those features that original Array has (like length autoincremention, splice, split etc.)

@kosich
kosich / RX_hold.js
Last active February 19, 2019 18:28
Pausable Observable that accumulates values. Run at https://observable-playground.github.io/gist/1d6bb94e2122d75fbbc51a52aafa50c7
const { rxObserver } = require('api/v0.3');
const { Observable, Subject, BehaviorSubject } = require('rxjs/Rx');
const trigger$ = Observable.of('o').delay(10);
const source$ = Observable.interval(3).take(5);
const afterTrigger$ = source$.skipUntil(trigger$);
const result$ =
source$
@kosich
kosich / index.js
Last active February 14, 2019 13:15
Observable that tracks its observers count. Run at https://observable-playground.github.io/gist/4a7415f3528aa125fb686204041138cb
const { chart } = require('rp-api');
const { Observable, timer, merge } = require('rxjs');
const { take } = require('rxjs/operators');
function createTrackedObservable(onEmpty) {
let count = 0;
return new Observable(() => {
count++;
return ()=>{
count--;
@kosich
kosich / index.js
Last active April 1, 2019 00:01
Switch sources on timeout
const { chart } = require('rp-api');
const { from, timer } = require('rxjs');
const { delayWhen, share, map, timeout, catchError, repeat, take } = require('rxjs/operators');
const source$ = from([ 5, 20, 25, 30, 42, 45 ])
.pipe(
delayWhen(timer)
, share()
);
const { chart } = require('rp-api');
const { forkJoin, of } = require('rxjs');
const { delay, tap, switchMap, mapTo } = require('rxjs/operators');
mockRequest(10, 'cid').pipe(
switchMap(id =>
forkJoin(
mockSendQueue([1, 2], id),
mockRequest(10, 'sub').pipe(
switchMap(subid =>
@kosich
kosich / index.js
Last active May 5, 2019 10:02
async error handler in RxJS
const { rxObserver } = require('api/v0.3');
const { timer, throwError } = require('rxjs');
const { mapTo, tap, catchError, switchMap } = require('rxjs/operators');
const error$ = timer(10).pipe(
switchMap(() => throwError('X'))
);
const omittedCatch$ = error$
.pipe(
const { rxObserver } = require('api/v0.3');
const { timer, throwError, of } = require('rxjs');
const { catchError, switchMap } = require('rxjs/operators');
const error$ = timer(5).pipe(
switchMap(() => throwError('X'))
);
error$.subscribe(rxObserver('Error'));