-
-
Save developer-rakeshpaul/0160a5c3f1fefd6ed2be8b8e6c7af193 to your computer and use it in GitHub Desktop.
Revisions
-
ssrdjan-fadv revised this gist
Feb 24, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ different implementations of the simple counter app... code verbosity vs expressiveness -
ssrdjan-fadv revised this gist
Feb 24, 2017 . 3 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes.File renamed without changes. -
ssrdjan-fadv revised this gist
Feb 24, 2017 . 4 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes. -
ssrdjan-fadv revised this gist
Feb 24, 2017 . 7 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes. -
ssrdjan-fadv revised this gist
Feb 24, 2017 . 9 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ Simple counter: different implementations... code verbosity vs expressiveness File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,4 +23,4 @@ function main(sources) { Cycle.run(main, { DOM: makeDOMDriver('#main-container') }); File renamed without changes.File renamed without changes.File renamed without changes. -
ssrdjan-fadv renamed this gist
Feb 23, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
ssrdjan-fadv renamed this gist
Feb 23, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
ssrdjan-fadv revised this gist
Feb 23, 2017 . 7 changed files with 2 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,4 +10,4 @@ export default ({value = U.atom(0)}) => <button onClick={() => value.modify(R.add(-1))}>-</button> </div> ReactDOM.render(<Main/>, document.getElementById("app")) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ data Action = Increment | Decrement type State = Int update :: Action -> State -> State update Increment count = count + 1 update Decrement count = count - 1 @@ -13,5 +12,4 @@ view count = [ button [ onClick (const Increment) ] [ text "Increment" ] , span [] [ text (show count) ] , button [ onClick (const Decrement) ] [ text "Decrement" ] ] File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes. -
ssrdjan-fadv renamed this gist
Feb 23, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
ssrdjan-fadv revised this gist
Feb 17, 2017 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,10 +6,10 @@ app({ add: model => model + 1, sub: model => model - 1 }, view: (model, actions) => <div> <button onclick={actions.add}>+</button> <h1>{model}</h1> <button onclick={actions.sub} disabled={model <= 0}>-</button> </div> }) -
ssrdjan-fadv revised this gist
Feb 12, 2017 . 2 changed files with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ Simple counter: different implementations... This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ import { h, app } from "hyperapp" app({ model: 0, update: { -
ssrdjan-fadv revised this gist
Feb 11, 2017 . 1 changed file with 8 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,12 +4,15 @@ import React from 'react' import {render} from 'react-dom' const state = { n: 0 }; const incr = () => state.n++; const decr = () => state.n--; const view = observer(() => <div> <h1>{state.n}</h1> <button onclick={incr}>+</button> <button onclick={decr}>-</button> </div>) render( <view />, -
ssrdjan-fadv revised this gist
Feb 11, 2017 . 9 changed files with 0 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,3 @@ import Dom exposing (..) import Lens exposing (Lens) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,3 @@ import * as R from "ramda" import * as U from "karet.util" import React from "karet" File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,3 @@ import { observable } from 'mobx'; import { observer } from 'mobx-react'; import React from 'react' File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,3 @@ import xs from 'xstream'; import Cycle from '@cycle/xstream-run'; import {div, button, p, makeDOMDriver} from '@cycle/dom'; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,3 @@ const choo = require('../../') const html = require('../../html') This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,3 @@ import Html exposing (Html, button, div, text) import Html.App as App import Html.Events exposing (onClick) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,3 @@ import React, { Component, PropTypes } from 'react' import ReactDOM from 'react-dom' import { createStore } from 'redux' -
ssrdjan-fadv revised this gist
Feb 11, 2017 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ app({ model: 0, update: { add: model => model + 1, sub: model => model - 1 }, view: (model, actions) => html` <div> <button onclick=${actions.add}>+</button> <h1>${model}</h1> <button onclick=${actions.sub} disabled=${model <= 0}>-</button> </div>` }) -
ssrdjan-fadv revised this gist
Nov 25, 2016 . 1 changed file with 12 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,28 +1,19 @@ / counter: mobx-react implementation import { observable } from 'mobx'; import { observer } from 'mobx-react'; import React from 'react' import {render} from 'react-dom' const state = { n: 0 }; const onclick = () => state.n++; const view = observer(() => <div> <h1>clicked {state.n} times</h1> <button onclick={onclick}>click me!</button> </div>) render( <view />, document.querySelector('#app') ); -
ssrdjan-fadv revised this gist
Nov 25, 2016 . 1 changed file with 17 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ data Action = Increment | Decrement type State = Int update :: Action -> State -> State update Increment count = count + 1 update Decrement count = count - 1 view :: State -> Html Action view count = div [] [ button [ onClick (const Increment) ] [ text "Increment" ] , span [] [ text (show count) ] , button [ onClick (const Decrement) ] [ text "Decrement" ] ]
-
ssrdjan-fadv revised this gist
Nov 15, 2016 . 1 changed file with 20 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ import React from 'react' export const init = count => count const Action = { Increment: x => x + 1, Decrement: x => x - 1 } export const update = (action, model) => action(model) export const view = (signal, model) => ( <div> <button onClick={signal(Action.Decrement)}>-</button> <div>{model}</div> <button onClick={signal(Action.Increment)}>+</button> </div> ) export default {init, update, view} -
ssrdjan-fadv revised this gist
Nov 13, 2016 . 2 changed files with 6 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,11 +2,14 @@ import * as R from "ramda" import * as U from "karet.util" import React from "karet" import ReactDOM from "react-dom" export default ({value = U.atom(0)}) => <div> <div>Count: {value}</div> <button onClick={() => value.modify(R.add(+1))}>+</button> <button onClick={() => value.modify(R.add(-1))}>-</button> </div> ReactDOM.render(<Main/>, document.getElementById("app")) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,7 @@ // counter: mobx implementation import { observable, autorun } from 'mobx'; import { diff, patch } from 'virtual-dom'; let mount = function mount(element, view, state) { let tree = <noop/>; -
ssrdjan-fadv revised this gist
Nov 13, 2016 . 1 changed file with 2 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,19 +15,16 @@ app.model({ }) const mainView = (state, prev, send) => { return html` <main class="app"> <button onclick=${() => send('increment')}>Increment</button> <button onclick=${() => send('decrement')}>Decrement</button> <p>state.counter</p> </main> } app.router((route) => [ route('/', mainView) ]) document.body.appendChild(app.start()) -
ssrdjan-fadv revised this gist
Nov 13, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,6 +21,7 @@ const mainView = (state, prev, send) => { <main class="app"> <button onclick=${() => send('increment')}>Increment</button> <button onclick=${() => send('decrement')}>Decrement</button> <p>count</p> </main> } -
ssrdjan-fadv revised this gist
Nov 13, 2016 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,5 @@ -- counter: calmm-js way ported to elm import Dom exposing (..) import Lens exposing (Lens) -
ssrdjan-fadv revised this gist
Nov 13, 2016 . 1 changed file with 4 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,18 +15,14 @@ type alias Model = Int model : Model model = 0 type Msg = Increment | Decrement update : Msg -> Model -> Model update msg model = case msg of Increment -> model + 1 Decrement -> model - 1 view : Model -> Html Msg view model = div [] -
ssrdjan-fadv revised this gist
Nov 13, 2016 . No changes.There are no files selected for viewing
-
ssrdjan-fadv revised this gist
Nov 13, 2016 . 6 changed files with 10 additions and 30 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ -- counter: calmm-js way ported to elm module Counter exposing (..) import Dom exposing (..) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ // counter: calmm-js import * as R from "ramda" import * as U from "karet.util" import React from "karet" This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ // counter: choo choo const choo = require('../../') const html = require('../../html') This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ // counter: cyclejs import xs from 'xstream'; import Cycle from '@cycle/xstream-run'; import {div, button, p, makeDOMDriver} from '@cycle/dom'; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,12 +11,10 @@ main = , update = update } type alias Model = Int model : Model model = 0 type Msg = Increment | Decrement @@ -29,7 +27,6 @@ update msg model = Decrement -> model - 1 view : Model -> Html Msg view model = div [] This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,37 +11,12 @@ class Counter extends Component { onDecrement: PropTypes.func.isRequired } render() { const { value, onIncrement, onDecrement } = this.props return ( <p> <button onClick={onIncrement}>+</button> <button onClick={onDecrement}>-</button> </p> ) } -
ssrdjan-fadv created this gist
Nov 13, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ module Counter exposing (..) import Dom exposing (..) import Lens exposing (Lens) counter : Lens m Int -> Html m counter value = div [] [ button [onClick (Lens.modify value ((+) -1))] [text "-"] , textAs toString value , button [onClick (Lens.modify value ((+) 1))] [text "+"] ] This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ import * as R from "ramda" import * as U from "karet.util" import React from "karet" export default ({value = U.atom(0)}) => <div> <div>Count: {value}</div> <button onClick={() => value.modify(R.add(+1))}>+</button> <button onClick={() => value.modify(R.add(-1))}>-</button> </div> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ const choo = require('../../') const html = require('../../html') const app = choo() app.model({ state: { counter: 0 }, reducers: { increment: (data, state) => ({ counter: state.counter + 1 }), decrement: (data, state) => ({ counter: state.counter - 1 }) } }) const mainView = (state, prev, send) => { const count = state.counter return html` <main class="app"> <button onclick=${() => send('increment')}>Increment</button> <button onclick=${() => send('decrement')}>Decrement</button> </main> } app.router((route) => [ route('/', mainView) ]) const tree = app.start() document.body.appendChild(tree) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ import xs from 'xstream'; import Cycle from '@cycle/xstream-run'; import {div, button, p, makeDOMDriver} from '@cycle/dom'; function main(sources) { let action$ = xs.merge( sources.DOM.select('.decrement').events('click').map(ev => -1), sources.DOM.select('.increment').events('click').map(ev => +1) ); let count$ = action$.fold((x,y) => x + y, 0); return { DOM: count$.map(count => div([ button('.decrement', 'Decrement'), button('.increment', 'Increment'), p('Counter: ' + count) ]) ) }; } Cycle.run(main, { DOM: makeDOMDriver('#main-container') }); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ -- counter: elm implementation import Html exposing (Html, button, div, text) import Html.App as App import Html.Events exposing (onClick) main = App.beginnerProgram { model = model , view = view , update = update } -- MODEL type alias Model = Int model : Model model = 0 -- UPDATE type Msg = Increment | Decrement update : Msg -> Model -> Model update msg model = case msg of Increment -> model + 1 Decrement -> model - 1 -- VIEW view : Model -> Html Msg view model = div [] [ button [ onClick Decrement ] [ text "-" ] , div [] [ text (toString model) ] , button [ onClick Increment ] [ text "+" ] ] This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ // counter: mobx implementation import { observable } from 'mobx'; import { diff, patch } from 'virtual-dom'; import { autorun } from 'mobx'; let mount = function mount(element, view, state) { let tree = <noop/>; function render() { const newTree = view(state); const patches = diff(tree, newTree); element = patch(element, patches); tree = newTree; } autorun(() => render()); } const state = { @observable n: 0 }; const onclick = () => state.n++; const view = (state) => <div> <h1>clicked {state.n} times</h1> <button onclick={onclick}>click me!</button> </div> mount( document.querySelector('#app'), view, state ); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,74 @@ // counter: redux implementation import React, { Component, PropTypes } from 'react' import ReactDOM from 'react-dom' import { createStore } from 'redux' class Counter extends Component { static propTypes = { value: PropTypes.number.isRequired, onIncrement: PropTypes.func.isRequired, onDecrement: PropTypes.func.isRequired } incrementIfOdd = () => { if (this.props.value % 2 !== 0) { this.props.onIncrement() } } incrementAsync = () => { setTimeout(this.props.onIncrement, 1000) } render() { const { value, onIncrement, onDecrement } = this.props return ( <p> Clicked: {value} times {' '} <button onClick={onIncrement}> + </button> {' '} <button onClick={onDecrement}> - </button> {' '} <button onClick={this.incrementIfOdd}> Increment if odd </button> {' '} <button onClick={this.incrementAsync}> Increment async </button> </p> ) } } const counter = (state = 0, action) => { switch (action.type) { case 'INCREMENT': return state + 1 case 'DECREMENT': return state - 1 default: return state } } const store = createStore(counter) const rootEl = document.getElementById('root') const render = () => ReactDOM.render( <Counter value={store.getState()} onIncrement={() => store.dispatch({ type: 'INCREMENT' })} onDecrement={() => store.dispatch({ type: 'DECREMENT' })} />, rootEl ) render() store.subscribe(render)