Skip to content

Instantly share code, notes, and snippets.

@taylorgorman
Last active June 1, 2019 19:25
Show Gist options
  • Save taylorgorman/1be0ea2e0bd113f13f5ea36209f743f8 to your computer and use it in GitHub Desktop.
Save taylorgorman/1be0ea2e0bd113f13f5ea36209f743f8 to your computer and use it in GitHub Desktop.
Optimistic vendor inclusion. After all, YOU are writing the files inside /vendor. Upside: cleaner Context.js. Downside: not evident in Context if missing functions.
import Auth0 from 'npm-auth0';
export isAuthenticated() {
// Access API with npm package
// API returns this function's required return, so we return directly
return Auth0.isAuthenticated();
}
import zillow_functions from 'vendor/zillow';
import auth0_functions from 'vendor/auth0';
import packageJson from '../package.json';
export class Provider extends Component {
state = {
app_title = 'Houses',
zip_code = 0,
version = packageJson.version
}
functions = {
// Assumes functions satisfy app requirements
// You'll want to document these requirements
...zillow_functions,
...auth0_functions,
// Then add functions unique to app
update_zip_code = ( zip_code ) => {
this.setState({ zip_code });
}
}
render(){ return (
<Context.Provider value={{
...this.state,
...this.functions
}}>{ this.props.children }</Context.Provider>
); }
};
import Zillow from 'npm-zillow';
export get_house_from_address ( address ) {
// Access API with npm package
const house = Zillow.get_houses_from_zip( address );
// Map to app's model
return {
bedrooms: house.bed_count,
bathrooms: house.bath_count,
isSold: house.status_sold,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment