Skip to content

Instantly share code, notes, and snippets.

// serverEvents.js
export function FOO_CREATED (event) {
return {
type: 'RECEIVE_FOO',
payload: {
foo: event.foo
}
}
}
var UserState = Marty.createStateMixin({
listenTo: [ActionStore, UserStore],
getState: function () {
return {
user: UserStore.getById(123),
createUser: ActionStore.getStatus(this.createUserToken)
};
}
})
var UsersStore = Marty.createStore({
handlers: {
addUser: [UserConstants.ADD_USER, UserConstants.CREATE_USER]
},
addUser: function (user) {
this.state[user.id] = user;
this.hasChanged();
return function actionFailed(error) {
this.state.errors[user.id] = error;
var ActionStore = require('marty/stores/actionStore');
var actionToken = ActionCreators.someAction();
ActionStore.addChangeListener(function () {
var action = ActionStore.getAction(actionToken);
console.log(action.status, action.error)
});
class Foo {
constructor() {
this.getFoo()
}
get getFoo() {
return function () {
console.log('foo');
}
}
@jhollingworth
jhollingworth / gist:701488f121af94694fb7
Created March 30, 2015 14:02
Add `locally` to fetch
import Marty from 'marty';
import OfferConstants from './OfferConstants';
import OfferQueries from './Queries';
class OffersStore extends Marty.Store {
constructor(options){
super(options);
this.state = [];

When I render OfferList through React Router, The result is a rejected promise, saying:

`An error occured when handling the DONE state of a fetch`

{
  message: "Not found",
  name: "Not found",
  status: 404

}

var UserStore = require('./stores/userStore');
var UserActions = require('./actions/userActions');
class Application extends Marty.Application {
constructor() {
super();
this.userStores = new UserStore({
app: this,
foo: "bar"
var UserStore = Marty.createStore({
id: 'UserStore',
getInitialState() {
return Immutable.Map()
},
dehyrdate() {
return this.state.toJS()
},
rehyrdate(state) {
this.replaceState(Immutable.fromJS(state))
let TestUtils = require("react/addons").addons.TestUtils;
class LoginPage extends React.Component {
render() {
return (
<form className="LoginPage">
<input type="email" value={this.state.email} />
<input type="password" value={this.state.password} />
<input type="submit" value="Login" />
</form>