GithubHelp home page GithubHelp logo

tiye / react-native-without-jsx-redux Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 90 KB

An React Native Demo without JSX and Redux

Python 12.40% Java 7.78% JavaScript 27.37% CoffeeScript 12.94% Objective-C 39.51%

react-native-without-jsx-redux's Introduction

An React Native Demo without JSX and Redux

Run with react-native run-ios.

emitter.js:

import EventEmitter from 'EventEmitter';
import Immutable from 'immutable';

let globalEmitter = new EventEmitter();

let register = fn => globalEmitter.addListener('bus', fn);

let unregisterAll = () => globalEmitter.removeAllListeners('bus');

let dispatch = (action, data) => globalEmitter.emit('bus', Immutable.fromJS([action, data]));

export { register };
export { unregisterAll };
export { dispatch };

container.js:

import React from 'react';
import hsl from 'hsl';
import { View, Text, TouchableHighlight, StyleSheet } from 'react-native';
import { register, dispatch, unregisterAll } from './emitter';
import { store } from './schema';
import { updater } from './updater/index';

let $ = React.createElement;

class Container extends React.Component {
  constructor(props) {
    super(props);
    this.state =
      {store};
  }

  componentDidMount() {
    return register(pair => {
      let [action, data] = pair;
      return this.setState({store: updater(this.state.store, action, data, null, null)});
    });
  }

  componentWillUnmount() {
    return unregisterAll();
  }

  onPress() {
    return dispatch('add', null);
  }

  render() {
    return $(View, {style: style.container},
      $(Text, {}, (JSON.stringify(this.state.store))),
      $(TouchableHighlight, {style: style.button, onPress: this.onPress.bind(this)},
        $(Text, {}, 'Add')));
  }
}

var style = StyleSheet.create({
  container: {
    paddingTop: 20
  },
  button: {
    backgroundColor: hsl(0,0,80),
    width: 100
  }
});

export default Container;

index.ios.js:

import React, { Component } from 'react';
import { AppRegistry } from 'react-native';

import Container from './app/container';

AppRegistry.registerComponent('Coffee', () => Container);

react-native-without-jsx-redux's People

Contributors

tiye avatar

Stargazers

 avatar

Watchers

 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.