Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Redux to Positron #1429

Merged
merged 7 commits into from
Nov 13, 2017
Merged

Add Redux to Positron #1429

merged 7 commits into from
Nov 13, 2017

Conversation

damassi
Copy link
Member

@damassi damassi commented Nov 10, 2017

This follows up on some convos and adds Redux into the mix with all of the standards / defaults.

Check out /edit to see it in action:

redux

Make sure to install Chrome's Redux Devtools!

screen shot 2017-11-09 at 6 04 31 pm

As more stuff moves into Redux this utility is incredible for getting an idea of whats happening in your app. No setup required when running in development mode 😎

In terms of testing, reach out to @sweir27 if you have any questions or check out her code: https://github.com/artsy/force/blob/master/desktop/apps/consign/test/reducers.js, https://github.com/artsy/force/blob/master/desktop/apps/consign/test/components.js

@damassi damassi requested a review from craigspaeth November 10, 2017 02:07
@ghost ghost assigned damassi Nov 10, 2017
@ghost ghost added the In progress label Nov 10, 2017
@damassi
Copy link
Member Author

damassi commented Nov 10, 2017

From a high-level perspective looking over the code y'all are in a very good place to make this a legit and super-snappy single-page app without even that much effort, assuming you follow the backbone - react pattern we've been using in Force. From client/assets/main.js:

Steps:

  1. Wrap existing Backbone route mount points around React similar to how we do it in force
  2. Ditch Backbone.Router
  3. Add isomorphic react router
  4. Move all of your express-based routes into a single route file (since there aren't many)
  5. Hydrate app in a similar fashion as other server-rendered react apps -- ReactDOM.renderToString and then re-mount on client. Since Backbone views are only mounted in componentDidMount, you'll have the full SSR flow and hydrated state ready populate with.
  6. Done!
  7. Bonus: Take advantage of webpack + dynamic import()'s to split your bundles up to make things even snappier / download size smaller. Can go right in react-router's route handlers with zero effort.

r =
find: ReactTestUtils.findRenderedDOMComponentWithClass
simulate: ReactTestUtils.Simulate
# _ = require 'underscore'
Copy link
Member Author

@damassi damassi Nov 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't have the time to figure out how to test non-jsx code... When y'all are done playing around with redux feel free to remove from sections i added it to and uncomment below test

})
})
})
// import React from 'react'
Copy link
Member Author

@damassi damassi Nov 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out for now; please uncomment after merged and finished testing out redux (don't have time atm to update tests for temporary examples)

@artsy-peril
Copy link
Contributor

artsy-peril bot commented Nov 10, 2017

New dependencies added: react-redux, redux, redux-logger, redux-thunk and updeep.

react-redux

Author: Dan Abramov

Description: Official React bindings for Redux

Homepage: https://github.com/gaearon/react-redux

Createdover 2 years ago
Last Updated6 days ago
LicenseMIT
Maintainers2
Releases64
Direct Dependencieshoist-non-react-statics, invariant, lodash, lodash-es, loose-envify and prop-types
Keywordsreact, reactjs, hot, reload, hmr, live, edit, flux and redux
README

React Redux

Official React bindings for Redux.
Performant and flexible.

build status npm version
npm downloads
redux channel on slack

Installation

React Redux requires React 0.14 or later.

npm install --save react-redux

This assumes that you’re using npm package manager with a module bundler like Webpack or Browserify to consume CommonJS modules.

If you don’t yet use npm or a modern module bundler, and would rather prefer a single-file UMD build that makes ReactRedux available as a global object, you can grab a pre-built version from cdnjs. We don’t recommend this approach for any serious application, as most of the libraries complementary to Redux are only available on npm.

React Native

As of React Native 0.18, React Redux 5.x should work with React Native. If you have any issues with React Redux 5.x on React Native, run npm ls react and make sure you don’t have a duplicate React installation in your node_modules. We recommend that you use npm@3.x which is better at avoiding these kinds of issues.

If you are on an older version of React Native, you’ll need to keep using React Redux 3.x branch and documentation because of this problem.

Documentation

How Does It Work?

We do a deep dive on how React Redux works in this readthesource episode.
Enjoy!

License

MIT

Generated by 🚫 dangerJS

@@ -13,7 +13,7 @@ import {
IconLayoutText
} from '@artsy/reaction-force/dist/Components/Publishing'

describe('Feature Header Controls', () => {
describe.skip('Feature Header Controls', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ Make sure to undo after merge and example code removed

@@ -11,7 +11,7 @@ const StandardArticle = Fixtures.StandardArticle

jest.mock('react-sizeme', () => jest.fn(c => d => d))

describe('Header', () => {
describe.skip('Header', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

r =
find: ReactTestUtils.findRenderedDOMComponentWithClass
simulate: ReactTestUtils.Simulate

describe 'EditContent', ->
xdescribe 'EditContent', ->
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

@damassi
Copy link
Member Author

damassi commented Nov 10, 2017

One more note: If you ever need to do form stuff -- small or large -- this library is the best https://redux-form.com/7.1.2/. Was used all over /consign and makes form building much more sane / fun.

article={article}
channel={channel}
/>
</Provider>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 SO EXCITING! 🎉

<button onClick={() => this.props.helloWorldAction({ status: 'Hi! ' + Math.random() })}>
Click me to update status!
</button>
</div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great! Can we remove this before merging though? content2 is being used as the default already which means it's visible to real people :P

@kanaabe
Copy link
Contributor

kanaabe commented Nov 10, 2017

This is so great! I like the examples you've set up around the project but as I've mentioned they'll be visible to the public so let's remove them before merging. The login/logout one might be fine to leave if you want since it's just a console output. Thanks so much for bringing Publishing to the next level! 🎉

@ghost ghost added the In progress label Nov 13, 2017
@kanaabe kanaabe merged commit 4077a42 into artsy:master Nov 13, 2017
@ghost ghost removed the In progress label Nov 13, 2017
@damassi damassi deleted the add-redux branch November 13, 2017 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants