Code Monkey home page Code Monkey logo

college-pantry's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

college-pantry's Issues

Some stuff I came up with

./index.ios.js and ./index.android.js are exactly the same.
Move that code exactly how it is into ./js/index.js(and export the component instead of doing AppRegistry...) then have each index.<platform>.js file look like such.

import React from 'react';
import CollegePantryReact from './js';

AppRegistry.registerComponent('collegePantryReact', () => CollegePantryReact);

Js naming conventions is PascalCase for classes
collegePantryReact should be CollegePantryReact

For the navigator renderScene prop(this is just a trick i've learned, not a standard), instead of having to do

if (route.name === ...) {
  return <... />
}
if (route.name === ...) {
  return <... />
}
...

you could give each component a route field that knows the component and anything else you need.

For example:

export default class Recipie extends Component {
  constructor(props) {
    super(props);
  }
  render() {
    return (
      <View style={styles.container}>
        <WebView
          source={{uri: this.props.recipie.source_url}}
          startInLoadingState={true}
          renderLoading={() => {return (<ActivityIndicator style={styles.loading} size="small" />)}}
        />
      </View>
    );
  }
}

could instead be

class Recipe extends Component {
  constructor(props) {
    super(props);
  }

  render() {
    return (
      <View style={styles.container}>
        <WebView
          source={{uri: this.props.recipie.source_url}}
          startInLoadingState={true}
          renderLoading={() => {return (<ActivityIndicator style={styles.loading} size="small" />)}}
        />
      </View>
    );
  }
}

Recipe.route = {
  component: Recipe,
  type: 'page',
  someOther: 'example data that might be useful'
};

export default Recipe;

You could do that for all top level components(components that are routes)

then on your navigator do initialRoute={SearchRecipe.route} instead of initialRoute={{ name: 'SearchRecipe', type: 'page' }}

and when you navigate do something like navigator.push(Recipe.route) instead of navigator.push({name: 'Recipe', ...})

and where you save big is in the renderScene method. All you'd need to do now is...

renderScene(route, navigator) {
  const RouteComponent = route.component;

  return <RouteComponent navigator={navigator} {...route.props} {...route.passProps}/>;
}

That's the way the current project I'm working on was set up before I came on. On the Laughly project I made I set up the routing in a way thats sort of a mixture of that way and yours. I had a routeMap that the navigator has access to and then I pull the component from the map instead of having to import the route for each scene in every file you want to navigate in. That looks a little like

const routeMap = {
  recipe: { component: Recipe, type: 'page', ...blah blah some useful data  },
  anotherRoute: {...},
  ...
};

then to navigate there this.props.navigator.push({name: 'recipe', otherStuffYouMayNeed: ...})
and then....

renderScene(route, navigator) {
  const RouteComponent = routeMap[route.name];

  return <RouteComponent navigator={navigator} {...route.props} {...route.passProps}/>;
}

Other than that it's just stuff like abstracting data fetching logic out of the actual view components and having that in its own area like ./js/api or ./js/services that you then import into the view files. Thats just organization stuff. Generally_(somewhat of an opinion here)_ the smaller the files the better it is.

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.