reactjs-flux

When to use .toJS() with Immutable.js and Flux?

一个人想着一个人 提交于 2019-12-03 02:12:48
问题 I'm trying to use ImmutableJS with my React / Flux application. My stores are Immutable.Map objects. I'm wondering at which point should I use .toJS() ? Should it be when the store's .get(id) returns ? or in the components with .get('member') ? 回答1: Ideally, never! If your Flux stores are using Immutable.js then try to maintain all the way through. Use React.addons.ReactComponentWithPureRenderMixin to achieve a memoization performance win (it adds a shouldComponentUpdate methods). When

Error Handler with Flux

本小妞迷上赌 提交于 2019-12-02 22:51:54
I have a React.js application that I am refactoring to use the Flux architecture, and am struggling to figure out how error handling should work while sticking to the Flux pattern. Currently when errors are encountered, a jQuery event 'AppError' is triggered and a generic Error Handling helper that subscribes to this event puts a Flash message on the user's screen, logs to the console, and reports it via an API call. What is nice is I can trigger an error for any reason from any part of the application and have it handled in a consistant way. I can't seem to figure out how to apply a similar

Flux/React Complex Reusable Component

拜拜、爱过 提交于 2019-12-02 20:59:39
I want to do something like this var App = React.createClass({ render: function() { return ( <CountryAutoComplete /> ) } }); Different app var App2 = React.createClass({ render: function() { return ( <CountryAutoComplete /> ) } }); Here is a simple Autocomplete (Not the entire file) var AutoComplete = React.createClass({ componentDidMount: function() { $(this.getDOMNode()).typeahead(this.props); }, render: function() { return ( <input type="text" class="typeahead" onChange={this.props.onChange} /> ); } }); The CountryAutoComplete would be something like this to be self contained. var

When to use .toJS() with Immutable.js and Flux?

感情迁移 提交于 2019-12-02 17:16:07
I'm trying to use ImmutableJS with my React / Flux application. My stores are Immutable.Map objects. I'm wondering at which point should I use .toJS() ? Should it be when the store's .get(id) returns ? or in the components with .get('member') ? Lee Byron Ideally, never! If your Flux stores are using Immutable.js then try to maintain all the way through. Use React.addons.ReactComponentWithPureRenderMixin to achieve a memoization performance win (it adds a shouldComponentUpdate methods). When rendering, you may need to call toJS() as React v0.12.x only accepts Array as children: render: function

Redux state persistence with a database

你说的曾经没有我的故事 提交于 2019-12-02 16:48:19
From the discussion here it seems that the state of Redux reducers should be persisted in a database. How does something like user authentication works in this instance? Wouldn't a new state object be created to replace the previous state in the database for every user (and their application state) created and edited? Would using all of this data on the front end and constantly updating the state in the database be performant? Edit: I've created an example Redux auth project that also happens to exemplify universal Redux, and realtime updating with Redux, Socket.io and RethinkDB. Alexander

How to submit a form using Enter key in react.js?

纵然是瞬间 提交于 2019-12-02 16:03:23
Here is my form and the onClick method. I would like to execute this method when the Enter button of keyboard is pressed. How ? N.B: No jquery is appreciated. comment: function (e) { e.preventDefault(); this.props.comment({comment: this.refs.text.getDOMNode().value, userPostId:this.refs.userPostId.getDOMNode().value}) }, <form className="commentForm"> <textarea rows="2" cols="110" placeholder="****Comment Here****" ref="text" /><br /> <input type="text" placeholder="userPostId" ref="userPostId" /> <br /> <button type="button" className="btn btn-success" onClick={this.comment}>Comment</button>

How to handle tree-shaped entities in Redux reducers?

為{幸葍}努か 提交于 2019-12-02 15:16:21
I'm a bit stuck thinking on how to implement a reducer where its entities can have children of the same type. Let's take reddit comments as an example: each comment can have child comments that can have comments themselves etc. For simplification reason, a comment is a record of type {id, pageId, value, children} , with pageId being the reddit page. How would one model the reducer around that? I was thinking of having the reducer be a map -> id of the comments where you can filter by page using the pageId . The issue is that for example when we want to add a comment to a nested one: we need to

Redux: Opinions/examples of how to do backend persistence?

你说的曾经没有我的故事 提交于 2019-12-02 14:17:29
I am wondering how folks using Redux are approaching their backend persistence. Particularly, are you storing the "actions" in a database or are you only storing the last known state of the application? If you are storing the actions, are you simply requesting them from the server, then replaying all of them when a given page loads? Couldn't this lead to some performance issues with a large scale app where there are lots of actions? If you are storing just the "current state", how are you actually persisting this state at any given time as actions happen on a client? Does anyone have some code

React router only works with root path

纵然是瞬间 提交于 2019-12-02 11:17:05
Only root route works. /about, /home shows "Cannot GET /home" in browser. If i replace each route path with "/" then the corresponding component is rendering. But there seems to be problem when i try to render certain route eg /home. You have to configure your server to work with Router.HistoryLocation -- that is, it needs to always serve your index.html page regardless of the route. app.get('*', function (req, res) { res.render('index'); }); Check out the docs here: React Router Docs - HistoryLocation 来源: https://stackoverflow.com/questions/32276514/react-router-only-works-with-root-path

POST a file with React.js

两盒软妹~` 提交于 2019-12-02 08:46:26
问题 The end user is supposed to upload through a file browser an excel file: <FloatingActionButton title="Upload excel" primary className="import-vendor" containerElement="label" label="Browse file"> <input onChange={(e) => Actions.uploadXLS(e.target.files[0])} type="file" name="xls" accept="application/vnd.ms-excel" style={{ display: 'none' }}/> <UploadIcon/> </FloatingActionButton> Action : uploadXLS(file) { this.getInstance().callUploadXLS( file ); } Service : callUploadXLS: { remote( state,