Skip to content

Instantly share code, notes, and snippets.

@jmas
jmas / stimulus.md
Created August 6, 2018 08:24 — forked from mrmartineau/stimulus.md
Stimulus cheatsheet
@jmas
jmas / index.html
Created July 30, 2018 16:23
Custom Elements
<my-list of="counters">
<template>
<my-counter index></my-counter>
</template>
</my-list>
<p>
<my-action on="click">
<button data-action="addCounter">
@jmas
jmas / errors.md
Last active April 19, 2018 09:08

Error classes

Can't parse

Broken JSON from backend.

General error

Contain errors._general key.

@jmas
jmas / events_draft.jsx
Last active April 4, 2018 23:36
alahaka.js
const edit = {
initialState: null,
actions: {
edit: something => state => something
},
view: (state, dispatch, connect) => (
<div>
Editing: {JSON.stringify(state)}
<button onClick={() => dispatch(edit.actions.edit({ name: 'Name!' }))}>Edit!</button>
</div>
@jmas
jmas / index.js
Last active March 23, 2018 09:47
const actions = createActionCreators({
createJob: (payload, actions) => async dispatch => {
dispatch(actions.createJobRequest())
const job = parseData(payload)
try {
const response = await api.jobs.create(job)
const body = await response.json()
if (response.status !== 200) {
throw new Error('Something went wrong')
}
@jmas
jmas / button.js
Created March 9, 2018 19:47
PoC: hyperapp + twitter bootstrap
import { h } from 'hyperapp';
export const BUTTON_VARIANT_PRIMARY = 'primary';
export const BUTTON_VARIANT_SECONDARY = 'secondary';
export const BUTTON_VARIANT_SUCCESS = 'success';
export const BUTTON_VARIANT_DANGER = 'danger';
export const BUTTON_VARIANT_WARNING = 'warning';
export const BUTTON_VARIANT_INFO = 'info';
export const BUTTON_VARIANT_LIGHT = 'light';
export const BUTTON_VARIANT_DARK = 'dark';
@jmas
jmas / reducer.js
Last active February 16, 2018 14:17
function processLoadingActions(loads, fails, successes, state, action) {
if (loads.indexOf(action.type) !== -1) {
return { ...state, isLoading: true };
}
if (fails.indexOf(action.type) !== -1) {
return { ...state, isLoading: false, error: action.error };
}
if (successes.indexOf(action.type) !== -1) {
return { ...state, isLoading: false, payload: action.payload };
}
@jmas
jmas / readme.md
Created February 12, 2018 21:53
How to start with react
  1. Install NodeJS from https://nodejs.org/uk/ (apt-get, brew)
  2. Should be shure that you have installed NPM
  3. npm install -g create-react-app
  4. create-react-app my-app
  5. cd ./my-app
@jmas
jmas / index.js
Last active January 16, 2018 14:21
// utils
function listenMessage(fromWhat, handler) {
fromWhat.addEventListener('message', ({data}) => {
const {type, payload} = data;
handler(type, payload);
});
}
function createFrame({
const withState = ({
initialState={},
actions={},
handleBeforeAction=null,
handleAfterAction=null,
}) => Component => (
class extends PureComponent {
state = initalState,
render() {