Giter Club home page Giter Club logo

sbnavigo's Introduction

tags

03_state.subscribe_to_innerHTML

import count_html from './count.html'
import Rx from 'rxjs/Rx';

const count = ()=>{
  document.querySelector('#rt').innerHTML = count_html
  var increaseButton = document.querySelector('#increase');
  var increase = Rx.Observable.fromEvent(increaseButton, 'click')
    .map(() => state => Object.assign({}, state, {count: state.count + 1}));

  var decreaseButton = document.querySelector('#decrease');
  var decrease = Rx.Observable.fromEvent(decreaseButton, 'click')
    .map(() => state => Object.assign({}, state, {count: state.count - 1}));

  var inputElement = document.querySelector('#inp');
  var input = Rx.Observable.fromEvent(inputElement, 'keypress')
    .map(event => state => Object.assign({}, state, {inputValue: event.target.value}));   

  var state = Rx.Observable
    .merge(increase, decrease, input)
    .scan((state, changeFn) => changeFn(state), {count: 0})

  state.subscribe((state) => {
    document.querySelector('#cnt').innerHTML = state.count;
    document.querySelector('#outp').innerHTML = 'Hello ' + state.inputValue;
  }); 
}

export {count }

02_count

we also need to handle is that multiple observables can update a single state store. http://reactivex.io/rxjs/manual/tutorial.html#creating-applications
NOT Quite each observable has its own version of ctx
import count_html from './count.html'
import Rx from 'rxjs/Rx';

const count = ()=>{
  document.querySelector('#rt').innerHTML = count_html
  var increaseButton = document.querySelector('#increase');
  Rx.Observable.fromEvent(increaseButton, 'click')
    .scan(cxt => cxt+1, 0)
    .subscribe(cxt=> document.querySelector('#cnt').innerHTML = cxt)
  var decreaseButton = document.querySelector('#decrease');
  Rx.Observable.fromEvent(decreaseButton, 'click')
    .scan(cxt => cxt-1, 0)
    .subscribe(cxt=> document.querySelector('#cnt').innerHTML = cxt)
};
export { count }

01_init_commit

DOESNT work with webpack devserver

  • navigo router using hash tags
  • imports RX and mqtt
  • imports es6 tagged templates and compiles template using let nav_templ = generateTemplateString(nav_html)({dog: 'Ulysses'})
  • setContent loads DOM, always with nav_templ
  • window.goprod needed for click function since webpack wraps its stuff so as not to be in the global window space
  • start router on load

.

  var init = function () {
    routing();
  };

window.onload = init;

broken for webpack.production.config, app.js:1Uncaught ReferenceError: useHash is not defined

router = new Navigo(null, true); works

import won't work unless query is in module

  module: {
    loaders: [
      { test: /\.js$/, 
        exclude: /node_modules/,
        loader: 'babel-loader' ,
        include: __dirname,
        query:
        {
          presets:['es2015']
        }
      },
      { test: /\.css$/, loader: "style!css?modules" },
      { test: /\.html$/, loader: "babel!es6-template-string?context=styles" }
    ],
  },  

sbnavigo's People

Contributors

mckennatim avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.