Skip to content

Instantly share code, notes, and snippets.

View oprearocks's full-sized avatar
🏖️
AFO — Away From the Office

Adrian Oprea oprearocks

🏖️
AFO — Away From the Office
View GitHub Profile
app.put('/user/:userId', (req, res) => {
User.findByIdAndUpdate(req.params.userId, $set: req.body.data, (updateFailedError, user) => {
if (updateFailedError) {
res
.status(500)
.json({
errors: [updateFailedError]
});
}
app.put('/user/:userId', (req, res) => {
User.update({ _id: req.params.userId }, $set: req.body.data, (updateFailedError) => {
if (updateFailedError) {
res
.status(500)
.json({
errors: [updateFailedError]
});
}
@oprearocks
oprearocks / mongoose_update_document_the_old_way.js
Last active June 9, 2017 22:38
A simpler way to update Mongodb documents
app.put('/user/:userId', (req, res) => {
User.findById(req.params.userId, (queryFailedError, user) => {
if (queryFailedError) {
res
.status(500)
.json({
errors: [queryFailedError]
});
}
// beware of dragons
// don't put your brackets on a new line
function actionCreator(data) {
return
{
type: 'EATEN_BY_A_DRAGON',
data
}
}
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
@oprearocks
oprearocks / handlers-map.jsx
Last active March 27, 2017 21:37
React.js Event Handlers Map
/**
* When writing event handlers it’s common to adopt the handle{eventName} naming convention.
*/
handleClick(e) { /* do something */ }
// For components that handle several event types, these function names can be repetitive. The names themselves might not provide much value, as they simply proxy to other actions/functions.
handleClick() { require("./actions/doStuff")(/* action stuff */) }
handleMouseEnter() { this.setState({ hovered: true }) }
handleMouseLeave() { this.setState({ hovered: false }) }

Folder Structure

Motivations

  • Clear feature ownership
  • Module usage predictibility (refactoring, maintainence, you know what's shared, what's not, prevents accidental regressions, avoids huge directories of not-actually-reusable modules, etc)
function fantasticMiddleware(req, res, next) {
console.log("I am fantastic!")
}
router.use("/listOrders", fantasticMiddleware);
router.use("/getTotal", fantasticMiddleware);
function fantasticMiddleware(req, res, next) {
console.log("I am fantastic!")
}
router.use(/^\/(listOrders|getTotal)\/?$/, fantasticMiddleware)