Skip to content

Instantly share code, notes, and snippets.

@gunnigylfa
gunnigylfa / App.re
Created October 19, 2018 14:44
How to initialize the app in App.re when using the stack navigator from `react-navigation`
let routeConfig: StackNavigatorRe.routesConfig = {
"main": {
"screen": Main.jsComponent,
"navigationOptions": {
"title": "",
},
},
"modal": {
"screen": Modal.jsComponent,
"navigationOptions": {
type iconConfig = {. "tintColor": string};
type routeConfig = {
.
"screen": ReasonReact.reactClass,
"navigationOptions": {. "title": string}
};
type navigator = {navigate: string => unit};

Keybase proof

I hereby claim:

  • I am gunnigylfa on github.
  • I am gunnigylfa (https://keybase.io/gunnigylfa) on keybase.
  • I have a public key ASCTBh2x_R_vTOFyKNFRVBdvPQv79wUtLRylZvnibEjjKgo

To claim this, I am signing this object:

@gunnigylfa
gunnigylfa / heroesDelete.js
Last active March 2, 2017 20:26
A remove operation for our Heroes API
// DELETE '/v1/heores/' Delete hero entry
api.delete('/:id', (req, res) => {
Hero.remove({
__id: req.params.id,
}, (err) => {
if (err) {
return res.send(err);
}
return res.json({
message: 'Hero successfully removed',
@gunnigylfa
gunnigylfa / heroesPut.js
Created March 2, 2017 18:41
Update a hero in our heroes API
// PUT '/v1/heroes' Update hero entry
api.put('/:id', (req, res) => {
Hero.findById(req.params.id, (err, hero) => {
if (err) {
return res.send(err);
}
hero.name = req.body.name;
hero.secretIdentity = req.body.name;
return hero.save((saveErr, savedHero) => {
@gunnigylfa
gunnigylfa / heroesGetById.js
Created March 2, 2017 18:18
A get by id resource for our heroes
// GET '/v1/heroes/:id' Get (Read) a specific heroe by ObjectId
api.get('/:id', (req, res) => {
Hero.findById(req.params.id, (err, hero) => {
if (err) {
return res.send(err);
}
return res.json(hero);
});
});
@gunnigylfa
gunnigylfa / heroesGet.js
Created March 1, 2017 22:20
A GET resource for our hero collection
// GET '/v1/heroes' Get (Read) all heroes
api.get('/', (req, res) => {
Hero.find({}, (err, heroes) => {
if (err) {
return res.send(err);
}
return res.json(heroes);
});
});
@gunnigylfa
gunnigylfa / heroesPost.js
Last active March 2, 2017 20:26
The post resource for our hero api
// POST '/v1/heroes' Create new hero entry
api.post('/', (req, res) => {
// Create a new blank Hero model
const newHero = new Hero();
// Fetch hero properties from the request body
newHero.name = req.body.name;
newHero.secretIdentity = req.body.secretIdentity;
// Save it in our database
newHero.save((err, hero) => {
if (err) {
@gunnigylfa
gunnigylfa / heroApi\controllers\heroes.js
Last active March 2, 2017 18:35
First iteration of our heroes controller
import { Router } from 'express';
import Hero from '../models/hero';
export default () => {
const api = Router();
// POST '/v1/heroes' Create new hero entry
// GET '/v1/heroes' Get (Read) all heroes
@gunnigylfa
gunnigylfa / index.js
Last active March 1, 2017 21:36
A main index file for our hero-api
import express from 'express';
import bodyParser from 'body-parser';
import config from './config';
import routes from './routes';
const app = express();
/*
* Send out a welcome message when the user hits our