Skip to content

Instantly share code, notes, and snippets.

View marcusradell's full-sized avatar

Marcus Rådell marcusradell

View GitHub Profile
@marcusradell
marcusradell / readme.md
Last active November 10, 2015 17:26
World Wild Web Development -Workshop

World Wild Web Development.

MDH Västerås, 10 november 2015.

Purpose.

tl;dr.

To give an overview of the technologies used in today's node.js web development.

Details

We will cover:

  • Source control. (Important.)
@marcusradell
marcusradell / root-project-waterline-shrink-wrap.json
Created January 12, 2016 11:55
waterline 0.10.28 shrinkwraps
{
"name": "waterline",
"version": "0.10.28",
"from": "waterline@0.10.28",
"resolved": "https://registry.npmjs.org/waterline/-/waterline-0.10.28.tgz",
"dependencies": {
"anchor": {
"version": "0.10.5",
"from": "anchor@>=0.10.2 <0.11.0",
"resolved": "https://registry.npmjs.org/anchor/-/anchor-0.10.5.tgz",
Barrels Error: Error (E_VALIDATION) :: 1 attribute is invalid
at WLValidationError.WLError (/Users/marcusnielsen/code/qvalia/qvalia-invoice-portal-mster-client-error/node_modules/sails/node_modules/waterline/lib/waterline/error/WLError.js:26:15)
at new WLValidationError (/Users/marcusnielsen/code/qvalia/qvalia-invoice-portal-mster-client-error/node_modules/sails/node_modules/waterline/lib/waterline/error/WLValidationError.js:20:28)
at /Users/marcusnielsen/code/qvalia/qvalia-invoice-portal-mster-client-error/node_modules/sails/node_modules/waterline/lib/waterline/query/validate.js:46:43
at allValidationsChecked (/Users/marcusnielsen/code/qvalia/qvalia-invoice-portal-mster-client-error/node_modules/sails/node_modules/waterline/lib/waterline/core/validations.js:210:5)
at /Users/marcusnielsen/code/qvalia/qvalia-invoice-portal-mster-client-error/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:49:16
at done (/Users/marcusnielsen/code/qvalia/qvalia-invoice-portal-ms

One paragraph rule

There are lots of rules of how to indent and divide rows of code into paragraphs. André Staltz suggested that we limit ourselves to 6 rows of code. I would try to stay in the working memory limit of 7 +/-2 bits according to Miller's law to keep cognitive strain down while reading other people's code. The number 6 still holds well enough, just want to add a reason for it.

One issue that might occurr, is that you need to return a function that has access to a variable on the parent scope:

@marcusradell
marcusradell / component-router.js
Created April 25, 2016 08:22
Componentized Express router
function create() {
var router = routerFactory.create()
router.get('/', onGetItems)
router.get('/verified', onGetVerifiedItems)
router.get('/status', onGetStatusList)
return {
router: router
}
@marcusradell
marcusradell / select-stream.js
Created November 17, 2016 14:56
rxjs select stream
export default function create({
Observable,
gridSelectStream,
newEntityResolveStream,
entityStoreStateStream
}) {
const newEntitySelectStream = newEntityResolveStream
.switchMap(function onSwitchMap(eventData) {
return entityStoreStateStream
.filter(function onFilter(entityStoreStateData) {

Observable components with React

Bring the fresh feel of React to the rest of your code

Abstract

From the Redux docs about Rx (http://redux.js.org/docs/introduction/PriorArt.html)

The question is: do you really need Redux if you already use Rx? Maybe not. It's not hard to re-implement Redux in Rx. Some say it's a two-liner using Rx .scan() method. It may very well be! [...] Let us know how it goes!

const initialState = {
byId: {}
}
export default class component extends React.Component {
constructor(props) {
super(props)
this.state = initialState
}
function reduce (state = initialState, action) {
switch (action.type) {
case types.add:
// ...
default:
return state
}
}