Code Monkey home page Code Monkey logo

react-mobx-shop's Issues

How to listen to "onAction" in mobx-state-tree branch

I'm try to add onAction from mobx-state-tree (in branch mobx-state-tree) to get complete snapshot of the store to send it via WebSockets. Here is an example.

onAction(shop, () => console.log('some action occurred'))

However, when app is starting i receive error message when go throughout navigation:

Uncaught Error: Argument 0 that was passed to action 'openBooksPage' should be a primitive, model object or plain object, received a SyntheticMouseEvent

How can i avoid this ?

UPDATE 1:

It also occurred when i reload page or updateBooks() triggered.

Thanks in advance

Complete error (updateBooks) msg Failed to load books Error: Argument 0 that was passed to action 'updateBooks' should be a primitive, model object or plain object, received a Array at serializeArgument (http://localhost:3000/static/js/bundle.js:40167:16) at http://localhost:3000/static/js/bundle.js:40213:68 at Array.map (native) at http://localhost:3000/static/js/bundle.js:40213:33 at runNextMiddleware (http://localhost:3000/static/js/bundle.js:40116:21) at runMiddleWares (http://localhost:3000/static/js/bundle.js:40120:13) at BookStore.actionInvoker (http://localhost:3000/static/js/bundle.js:40141:25) at BookStore.updateBooks (eval at createNamedFunction (http://localhost:3000/static/js/bundle.js:1:1), :3:42) at http://localhost:3000/static/js/bundle.js:49546:20
Complete error (navigation) msg Uncaught Error: Argument 0 that was passed to action 'openBooksPage' should be a primitive, model object or plain object, received a SyntheticMouseEvent at serializeArgument (http://localhost:3000/static/js/bundle.js:40163:16) at http://localhost:3000/static/js/bundle.js:40209:68 at Array.map (native) at http://localhost:3000/static/js/bundle.js:40209:33 at runNextMiddleware (http://localhost:3000/static/js/bundle.js:40112:21) at runMiddleWares (http://localhost:3000/static/js/bundle.js:40116:13) at AnonymousModel.actionInvoker (http://localhost:3000/static/js/bundle.js:40137:25) at AnonymousModel.openBooksPage (eval at createNamedFunction (http://localhost:3000/static/js/bundle.js:39117:13), :3:44) at Object.ReactErrorUtils.invokeGuardedCallback (http://localhost:3000/static/js/bundle.js:17166:17) at executeDispatch (http://localhost:3000/static/js/bundle.js:16949:22)
Complete index.js import React from 'react' import ReactDOM from 'react-dom' import { Provider } from 'mobx-react' import { reaction } from 'mobx'

import createRouter from './utils/router'
import App from './components/App'
import './index.css'

import { getSnapshot, onAction } from 'mobx-state-tree';

import { ShopStore } from './stores/ShopStore'

const fetcher = url => window.fetch(url).then(response => response.json())
const shop = ShopStore.create({}, {
fetch: fetcher,
alert: m => window.alert(m)
})
window.shop = shop // for playing around

ReactDOM.render(


,
document.getElementById('root')
)

onAction(shop, () => console.log('some action occurred'))

reaction(
() => shop.view.currentUrl,
(path) => {
if (window.location.pathname !== path)
window.history.pushState(null, null, path)
}
)

const router = createRouter({
"/book/:bookId": ({bookId}) => shop.view.openBookPageById(bookId),
"/cart": shop.view.openCartPage,
"/": shop.view.openBooksPage
})

window.onpopstate = function historyChange(ev) {
if (ev.type === "popstate")
router(window.location.pathname)
}

router(window.location.pathname)

withDefaults does not exist on types

Hi, I am trying to port this to Typescript, but the types.withDefault does not exist there (in definition).
What is another ways of specifying sub - model of a model?

would this be right ?

import { types, getEnv } from "mobx-state-tree"
import { BookStore } from './BookStore'
import { CartStore } from './CartStore'
import { ViewStore } from './ViewStore'

export const ShopStore = types.model("ShopStore", {
    bookStore: BookStore.create(),
    cart: CartStore.create(),
    view: ViewStore.create(),
}
...

[EDIT] This not a way to go since I receive error: Error: [mobx-state-tree] In property 'xxx': base model's should not contain complex values:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.