This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const RECEIVE_MESSAGE = 'RECEIVE_MESSAGE'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// koa-passport-authenticate.js | |
'use strict' | |
const _ = require('lodash') | |
const passport = require('koa-passport') | |
'use strict' | |
// Middleware wrapper for koa passport to have proper error handling on authenticate. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple Event emitter realization | |
class EventEmitter { | |
constructor() { | |
// store for handlers | |
this.events = {}; | |
} | |
// subscribe | |
on(name, fn) { | |
this.events[name] = this.events[name] || []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// make EE singelton, add .off method | |
let instance = null; | |
class EventEmitter { | |
constructor() { | |
// ensure we have only one instance (singelton pattern) | |
if (!instance) { | |
instance = this; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// trun {fiels: {email: 'val', err:''}} to {email: 'val'} | |
var getValues = () => { | |
let data = {}; | |
let form = toJS(this.form).fields; | |
Object.keys(form).map(key => { | |
data[key] = form[key].value | |
}); | |
return data | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { observable } from 'mobx' | |
export default class LoginStore { | |
@observable | |
form = { | |
fields: { | |
email: { | |
value: '', // binds to input value | |
error: null // shows beneif the input | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Validator from 'validatorjs' | |
var data = { | |
name: 'John', | |
email: 'not-valid-email' | |
}; | |
var rules = { | |
name: 'required', | |
email: 'required|email' | |
}; | |
var validation = new Validator(data, rules); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<FormInput name="name" | |
value={form.fields.name.value} | |
error={form.fields.name.error} | |
onChange={form.onFieldChange} | |
placeholder="Enter your name"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { PropTypes } from 'react'; | |
import classNames from 'classnames' | |
let getFormInputClasses = ({valid, error}) => classNames('form-input', { | |
'form-input--error': !!error, | |
}) | |
let FormInput = (props) => ( | |
<span className={getFormInputClasses(props)}> | |
<input {...props} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {action, observable} from 'mobx'; | |
import Validator from 'validatorjs'; | |
class LoginStore { | |
@observable | |
form = { | |
fields: { | |
email: { | |
value: '', | |
error: null, |
OlderNewer