Skip to content

Instantly share code, notes, and snippets.

View alexvcasillas's full-sized avatar
🏠
Working from home

Alex Casillas alexvcasillas

🏠
Working from home
View GitHub Profile
@alexvcasillas
alexvcasillas / language_store.js
Last active March 13, 2017 08:23
Language Store in MobX
import { observable, computed, action, reaction } from 'mobx';
import esES from '../language/i18n/es';
import enUS from '../language/i18n/en';
export default class LanguageStore {
@observable language;
@computed get resource() {
switch (this.language) {
@alexvcasillas
alexvcasillas / styled-button.jsx
Last active April 28, 2017 11:36
Little question about Styled-Components integration with MobX
import { inject, observer } from 'mobx-react';
import styled from 'styled-components';
const Button = styled.button`
background: linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%);
border-radius: ${props => props.ui.borderRadius}px;
border: 0;
outline: none;
color: ${props => props.ui.textColor};
text-transform: uppercase;
@alexvcasillas
alexvcasillas / github-store.js
Created May 4, 2017 08:35
Async Fetching with MobX Actions
import fetch from 'node-fetch';
import { observable, action, runInAction } from 'mobx';
export default class GithubStore {
@observable searchName;
@observable user;
@observable repos;
@observable fetchingData;
constructor() {
@alexvcasillas
alexvcasillas / GithubStore.js
Last active May 12, 2017 16:20
Migrating mobx to mobx-state-tree
/**
* mobx store migration to mobx-state-tree system
**/
// Original MobX Store
import { observable, action, runInAction } from 'mobx';
export default class GithubStore {
@observable searchName;
@alexvcasillas
alexvcasillas / GithubStore.js
Last active May 15, 2017 07:28
Having an error while migrating mobx to mobx-state-tree and store.create({})
/**
* UPDATED ERROR WITH MOBX-STATE-TREE v0.6.1
**/
// Store that throws this error.
import { runInAction } from 'mobx';
import { types } from 'mobx-state-tree';
const GithubStore = types.model(
'GithubStore',
utils.js:14 Uncaught (in promise) Error: [mobx-state-tree] Cannot modify 'GithubStore@<root>', the object is protected and can only be modified by using an action.
at invariant (utils.js:14)
at Object.fail (utils.js:6)
at MSTAdministration.assertWritable (mst-node-administration.js:334)
at ObjectType.willChange (object.js:76)
at Array.<anonymous> (object.js:70)
at interceptChange (mobx.js:1461)
at setPropertyValue (mobx.js:2383)
at GithubStore.set [as user] (mobx.js:2363)
at github.js:34
@alexvcasillas
alexvcasillas / store-observable-null.js
Created May 17, 2017 09:31
Check for an observable null value
// This is the store
import fetch from 'node-fetch';
import { types } from 'mobx-state-tree';
const UserModel = types.model(
'UserModel',
{
name: types.string,
bio: types.maybe(types.string),
avatar: types.string
@alexvcasillas
alexvcasillas / types-explode.js
Created May 17, 2017 10:05
Using types.maybe(UserModel) explodes
Uncaught Error: [mobx-state-tree] Error while converting `{"searchName":"","user":{},"repos":[],"fetchingData":false}` to `GithubStore`:
at path "/user" snapshot `{}` is not assignable to type: `UserModel | null`, expected an instance of `UserModel | null` or a snapshot like `({ name: string; bio: (string | null?); avatar: string } | null?)` instead.
@alexvcasillas
alexvcasillas / githubstore-creation.js
Created May 17, 2017 10:10
Creation of the GithubStore
const githubStore = GithubStore.create({
searchName: '',
user: {},
repos: [],
fetchingData: false
});
@alexvcasillas
alexvcasillas / withspectrum-raven-error.js
Last active May 17, 2017 13:04
Error at With Spectrum.
raven.js:51 Caught an exception! TypeError: Cannot read property 'slug' of undefined
at Object.r.renderStory [as elementRenderer] (index.js:204)
at renderElement (index.js:78)
at t.value (List.js:124)
at r (defaultCellRangeRenderer.js:107)
at t.value (Grid.js:632)
at t.value (Grid.js:475)
at f._performComponentUpdate (ReactCompositeComponent.js:714)
at f.updateComponent (ReactCompositeComponent.js:645)
at f.receiveComponent (ReactCompositeComponent.js:547)