Skip to content

Instantly share code, notes, and snippets.

function loadSomeStuff(id) {
// We return basic-stream https://github.com/rpominov/basic-streams
return _sink => {
let sink = _sink
const onSuccess = data => sink({type: 'success', data})
const onError = error => sink({type: 'error', error})
stuffLoadingService.load(id).done(onSuccess, onError)
return () => {
// We can't unsubscribe from a Promise, so we simply make sink() a noop
sink = () => {}
/* @flow */
type Sink<T> = (payload: T) => void
type Disposer = () => void
type Stream<T> = (s: Sink<T>) => Disposer
type F<A, B> = (x: A) => B
type LiftedF<A, B> = (s: Stream<A>) => Stream<B>
/* Lifts function `A => B` to a funcion that operates
@rpominov
rpominov / bacon-animation-frames.coffee
Created December 21, 2013 20:08
Bacon.js requestAnimationFrame
Bacon.fromBinder (sink) ->
request =
window.requestAnimationFrame or
window.webkitRequestAnimationFrame or
window.mozRequestAnimationFrame or
window.oRequestAnimationFrame or
window.msRequestAnimationFrame or
(f) -> window.setTimeout(f, 1000 / 60)
subscribed = true
handler = ->
@rpominov
rpominov / bacon-swipes-and-drags.coffee
Last active January 1, 2016 01:39
Bacon.js swipes and mouse-drags
do (exports = window.baconSwipes = {}) ->
getPos = (e) ->
source = (if e.originalEvent.touches
e.originalEvent.touches[0]
else
e.originalEvent)
x: source.clientX
y: source.clientY
event: e
@rpominov
rpominov / gist:6489439
Created September 8, 2013 23:15
impossibear.js concept
<div class="js-spoiler">
<button class="js-toggle">скрыть/показать</button>
<p class="js-content">контент контент контент</p>
</div>
catbug """
.js-spoiler
.js-toggle
.js-content
""", ->
@rpominov
rpominov / bookmark.url
Last active December 10, 2015 18:29
Help read bookmarklet
javascript:(function()%7Bvar%20script%3Ddocument.createElement(%27script%27)%3Bscript.src%3D%27https://gist.github.com/raw/4475306/readhelp.js%3F%27%2BMath.floor((%2Bnew%20Date)/(864e5))%3Bdocument.body.appendChild(script)%3B%7D)()
@rpominov
rpominov / containers-and-pure-views-in-react.md
Last active November 23, 2015 09:56
About containers VS pure views in React (an untested idea)
  1. If it works for you just use single container on top of each route, othervise see 2
  2. Wrap a view into container whenever necessary, but always pass wrapped component via props:
// pure component's render
<foo>
  <bar>
    {this.props.someWrappedChild}
  </bar>
@rpominov
rpominov / 01-react-testing.md
Last active November 1, 2015 11:43
React testing ideas

Stateles components

// mark relevant parts of result tree with __tetsId & __testClass
const TestTarget = props => 
  <div>
    <Foo foo={props.foo} __tetsId="foo" />
    <ul>
      <li num={1} __testClass="baz" />
      <li num={2} __testClass="baz" />
@rpominov
rpominov / ReactDemo.js
Created July 18, 2015 10:53
React-demo concept
/* Will render <Counter/>, a number input,
* and a log-output widget with all onChange calls e.g.
* > onChange(1)
* > onChange(2)
*/
<Demo
target={Counter}
props={{
count: Demo.props.int.arbitrary
onChange: Demo.props.callback.log
@rpominov
rpominov / react-draggable-concept.md
Created October 27, 2015 23:43
React draggable concept