Last active
March 30, 2018 03:23
-
-
Save hiroykam/9c58ea06534e402506c1d598937393d8 to your computer and use it in GitHub Desktop.
React/Reduxのtips ref: https://qiita.com/hiroykam/items/03d6f0b75f55b677c464
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const PREPARE1 = "PREPARE1" | |
| export const PREPARE2 = "PREPARE2" | |
| export const MESSAGE1 = "MESSAGE1" | |
| export const MESSAGE2 = "MESSAGE2" | |
| const preparemessages = (n) => { | |
| const state = (n == 1) ? PREPARE1 : PREPARE2 | |
| return { | |
| type: state | |
| } | |
| } | |
| const createMessages = (n, arr = []) => { | |
| let lst = arr || [] | |
| let start = arr.length + 1 | |
| for (let i = start; i < start + 20; i++) { | |
| lst.push(i) | |
| } | |
| const state = (n == 1) ? MESSAGE1 : MESSAGE2 | |
| return { | |
| type: state, | |
| msg: lst | |
| } | |
| } | |
| export const loadMore = (n) => { | |
| return (dispatch, getState) => { | |
| dispatch(preparemessages(n)) | |
| let messages = (n == 1) ? getState().demo.messages1 : getState().demo.messages2 | |
| setTimeout(() => { | |
| dispatch(createMessages(n, messages)) | |
| }, 1000) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react' | |
| import { render } from 'react-dom' | |
| import { Provider } from 'react-redux' | |
| import { createStore, applyMiddleware } from 'redux' | |
| import thunk from 'redux-thunk' | |
| import reducer from './reducer.jsx' | |
| import DemoContainer from './container.jsx' | |
| const store = createStore(reducer, applyMiddleware(thunk)) | |
| render ( | |
| <Provider store={ store }> | |
| <DemoContainer /> | |
| </Provider>, | |
| document.querySelector('.react_scroll') | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function() { | |
| this.App || (this.App = {}); | |
| App.cable = ActionCable.createConsumer(); | |
| }).call(this); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react' | |
| import { connect } from 'react-redux' | |
| import { bindActionCreators } from 'redux' | |
| import * as actions from './actions.jsx' | |
| import ReduxInfiniteScroll from 'redux-infinite-scroll' | |
| import ReduxInfiniteScrollEx from './ReduxInfiniteScrollEx.jsx' | |
| class DemoContainer extends Component { | |
| render() { | |
| const { demo, actions } = this.props | |
| const _renderMessages = (messages) => { | |
| return messages.map((msg) => { | |
| return( | |
| <div className="item" key={msg}>{msg}</div> | |
| ) | |
| }) | |
| } | |
| return ( | |
| <div style={{ width: "300px", marginLeft: "200px" }} > | |
| <ReduxInfiniteScroll loadingMore={ demo.loadingMore1 } containerHeight="300px" loadMore={ () => actions.loadMore(1) } > | |
| { _renderMessages(demo.messages1) } | |
| </ReduxInfiniteScroll> | |
| <br /> | |
| <ReduxInfiniteScrollEx loadingMore={ demo.loadingMore2 } containerHeight="300px" loadMore={ () => actions.loadMore(2) } > | |
| { _renderMessages(demo.messages2) } | |
| </ReduxInfiniteScrollEx> | |
| </div> | |
| ) | |
| } | |
| } | |
| const mapState = (state) => ({ | |
| demo: state.demo | |
| }) | |
| const mapDispatch = (dispatch) => ({ | |
| actions: bindActionCreators(actions, dispatch) | |
| }) | |
| export default connect(mapState, mapDispatch)(DemoContainer) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default ({ | |
| suggestions: { | |
| display: "inline-block", | |
| position: "unset", | |
| float: "left", | |
| overflow: "scroll", | |
| maxHeight: "300px", | |
| marginLeft: "50%", | |
| list: { | |
| display: "inline-block", | |
| position: "unset", | |
| float: "left", | |
| backgroundColor: 'white', | |
| fontSize: 10, | |
| }, | |
| item: { | |
| position: "relative", | |
| '&focused': { | |
| backgroundColor: '#cee4e5', | |
| }, | |
| }, | |
| } | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ yarn add --dev babel-preset-stage-2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ npm install --save-dev babel-preset-stage-2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TestContainer extends Component { | |
| componentDidMount() { | |
| const { actions } = this.props | |
| actions.testMethod() | |
| } | |
| render() { | |
| return ( | |
| <div>test</div> | |
| ) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ yarn add --dev redux-shortcuts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react' | |
| export const comp = ({ json }) => { | |
| const mu = Object.keys(json).map((key) => { | |
| return ( | |
| <div key={ key } > | |
| <img src={ json[key].icon } /><br /> | |
| </div> | |
| ) | |
| }) | |
| return ( | |
| <div> | |
| { mu } | |
| </div> | |
| ) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ npm install --save-dev redux-shortcuts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react' | |
| export const comp = ({ json }) => { | |
| const mu = Object.keys(json).map((key) => { | |
| return ( | |
| <div key={ key } > | |
| <img src={ json[key].icon } /><br /> | |
| </div> | |
| ) | |
| }) | |
| return ( | |
| <div> | |
| { mu } | |
| </div> | |
| ) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ yarn add --dev redux-shortcuts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ npm install --save-dev redux-shortcuts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { bindShortcuts } from 'redux-shortcuts' | |
| import { dispatchTest } from './actions' | |
| import { reducer } from './reducer' | |
| const store = createStore(reducer, applyMiddleware(thunk)) | |
| bindShortcuts( | |
| [['command+d', 'ctrl+d'], dispatchTest] | |
| )(store.dispatch) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ npm install --save-dev redux-shortcuts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { bindShortcuts } from 'redux-shortcuts' | |
| import { dispatchTest } from './actions' | |
| import { reducer } from './reducer' | |
| const store = createStore(reducer, applyMiddleware(thunk)) | |
| bindShortcuts( | |
| [['command+d', 'ctrl+d'], dispatchTest] | |
| )(store.dispatch) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ yarn add --dev redux-devtools | |
| $ yarn add --dev redux-devtools-log-monitor | |
| $ yarn add --dev redux-devtools-dock-monitor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ npm install --save-dev redux-devtools | |
| $ npm install --save-dev redux-devtools-log-monitor | |
| $ npm install --save-dev redux-devtools-dock-monitor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ npm install --save-dev redux-devtools | |
| $ npm install --save-dev redux-devtools-log-monitor | |
| $ npm install --save-dev redux-devtools-dock-monitor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ yarn init | |
| $ yarn add --dev webpack | |
| $ yarn add --dev react react-dom redux react-redux redux-thunk | |
| $ yarn add --dev babel-loader babel-core babel-preset-es2015 babel-preset-react babel-preset-stage-2 | |
| $ yarn add --dev style-loader css-loader | |
| $ yarn add --dev react-mentions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ yarn init | |
| $ yarn add --dev webpack | |
| $ yarn add --dev react react-dom redux react-redux redux-thunk | |
| $ yarn add --dev babel-loader babel-core babel-preset-es2015 babel-preset-react babel-preset-stage-2 | |
| $ yarn add --dev style-loader css-loader | |
| $ yarn add --dev react-mentions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ yarn init | |
| $ yarn add --dev webpack | |
| $ yarn add --dev react react-dom redux react-redux redux-thunk | |
| $ yarn add --dev babel-loader babel-core babel-preset-es2015 babel-preset-react babel-preset-stage-2 | |
| $ yarn add --dev style-loader css-loader | |
| $ yarn add --dev redux-infinite-scroll |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ yarn run prod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ yarn init | |
| $ yarn add --dev webpack | |
| $ yarn add --dev react react-dom redux react-redux redux-thunk | |
| $ yarn add --dev babel-loader babel-core babel-preset-es2015 babel-preset-react babel-preset-stage-2 | |
| $ yarn add --dev style-loader css-loader | |
| $ yarn add --dev redux-infinite-scroll |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ yarn run prod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ yarn init | |
| $ yarn add --dev webpack | |
| $ yarn add --dev react react-dom redux react-redux redux-thunk | |
| $ yarn add --dev babel-loader babel-core babel-preset-es2015 babel-preset-react babel-preset-stage-2 | |
| $ yarn add --dev style-loader css-loader | |
| $ yarn add --dev redux-infinite-scroll |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .redux-infinite-scroll { | |
| overflow: scroll; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ yarn run prod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ yarn init | |
| $ yarn add --dev webpack | |
| $ yarn add --dev react react-dom redux react-redux redux-thunk | |
| $ yarn add --dev babel-loader babel-core babel-preset-es2015 babel-preset-react babel-preset-stage-2 | |
| $ yarn add --dev style-loader css-loader | |
| $ yarn add --dev redux-infinite-scroll |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .redux-infinite-scroll { | |
| overflow: scroll; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ yarn init | |
| $ yarn add --dev webpack | |
| $ yarn add --dev react react-dom redux react-redux redux-thunk | |
| $ yarn add --dev babel-loader babel-core babel-preset-es2015 babel-preset-react babel-preset-stage-2 | |
| $ yarn add --dev style-loader css-loader | |
| $ yarn add --dev redux-infinite-scroll |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| return (<div className={ `uk-navbar-nav uk-hidden-small`} />) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| return (<div className={ `uk-navbar-nav uk-hidden-small`} />) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .redux-infinite-scroll { | |
| overflow: scroll; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ yarn run prod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const ChatChannel = App.cable.subscriptions.create({channel: "ChatChannel" }, | |
| { | |
| connected: () => { | |
| console.log("connected") | |
| }, | |
| disconnected: () => { | |
| console.log("disconnected") | |
| }, | |
| received: (data) => { | |
| console.log("received", data) | |
| }, | |
| speak: () => { | |
| return (dispatch, getState) => { | |
| const msg = getState().demo.msg | |
| BrandChannel.perform('speak', { msg }) | |
| console.log("speak") | |
| } | |
| } | |
| } | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ yarn run prod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const ChatChannel = App.cable.subscriptions.create({channel: "ChatChannel" }, | |
| { | |
| connected: () => { | |
| console.log("connected") | |
| }, | |
| disconnected: () => { | |
| console.log("disconnected") | |
| }, | |
| received: (data) => { | |
| console.log("received", data) | |
| }, | |
| speak: () => { | |
| return (dispatch, getState) => { | |
| const msg = getState().demo.msg | |
| BrandChannel.perform('speak', { msg }) | |
| console.log("speak") | |
| } | |
| } | |
| } | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ yarn run prod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ yarn run prod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| return (<div style={{ textAlign: 'center', margin: '10px 0px' }} />) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const navi = "uk-navbar-nav" | |
| const opt = "uk-hidden-small" | |
| return (<div className={ `${navi} ${opt}`} />) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const ChatChannel = App.cable.subscriptions.create({channel: "ChatChannel" }, | |
| { | |
| connected: () => { | |
| console.log("connected") | |
| }, | |
| disconnected: () => { | |
| console.log("disconnected") | |
| }, | |
| received: (data) => { | |
| console.log("received", data) | |
| }, | |
| speak: () => { | |
| return (dispatch, getState) => { | |
| const msg = getState().demo.msg | |
| BrandChannel.perform('speak', { msg }) | |
| console.log("speak") | |
| } | |
| } | |
| } | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const ChatChannel = App.cable.subscriptions.create({channel: "ChatChannel" }, | |
| { | |
| connected: () => { | |
| console.log("connected") | |
| }, | |
| disconnected: () => { | |
| console.log("disconnected") | |
| }, | |
| received: (data) => { | |
| console.log("received", data) | |
| }, | |
| speak: () => { | |
| return (dispatch, getState) => { | |
| const msg = getState().demo.msg | |
| BrandChannel.perform('speak', { msg }) | |
| console.log("speak") | |
| } | |
| } | |
| } | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| return (<div style={{ textAlign: 'center', margin: '10px 0px' }} />) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const navi = "uk-navbar-nav" | |
| const opt = "uk-hidden-small" | |
| return (<div className={ `${navi} ${opt}`} />) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| return (<div style={{ textAlign: 'center', margin: '10px 0px' }} />) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| return ( | |
| <div className="test"> | |
| <div className="test-title"> | |
| <i className="test-icon" /> | |
| </div> | |
| {/* | |
| <div className="test-body"> | |
| <p>test body</p> | |
| </div> | |
| */} | |
| <div className="test-comment"> | |
| {// <p>test comment</p> | |
| } | |
| </div> | |
| </div> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| return ( | |
| <div className="test"> | |
| <div className="test-title"> | |
| <i className="test-icon" /> | |
| </div> | |
| {/* | |
| <div className="test-body"> | |
| <p>test body</p> | |
| </div> | |
| */} | |
| <div className="test-comment"> | |
| {// <p>test comment</p> | |
| } | |
| </div> | |
| </div> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { state } from 'state' | |
| const test1 = () => { | |
| return { | |
| type: state.TEST1 | |
| } | |
| } | |
| const test2 = () => { | |
| return { | |
| type: state.TEST2 | |
| } | |
| } | |
| const dispatchTest = () => { | |
| return (dispatch, getState) => { | |
| if (getState().myState.type === state.TEST1) { | |
| dispatch(test2()) | |
| } else { | |
| dispatch(test1()) | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ yarn add --dev redux-shortcuts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { state } from 'state' | |
| import { store } from 'store' | |
| const dispatchTest = () => { | |
| if (store.getState().myState.type === state.TEST1) { | |
| return { | |
| type: state.TEST2 | |
| } | |
| } else { | |
| return { | |
| type: state.TEST1 | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ npm install --save-dev redux-shortcuts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <title>React infnite scroll test</title> | |
| <link rel="stylesheet" type="text/css" href="css/main.css" media="screen"> | |
| <link rel="stylesheet" type="text/css" href="css/stylesheet.css" media="screen"> | |
| </head> | |
| <body> | |
| <div class="react_scroll"></div> | |
| <script type="text/javascript" src="js/app.bundle.js"></script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "infinite_scroll", | |
| "version": "1.0.0", | |
| "main": "index.js", | |
| "license": "MIT", | |
| "devDependencies": { | |
| "babel-core": "^6.26.0", | |
| "babel-loader": "^7.1.2", | |
| "babel-preset-es2015": "^6.24.1", | |
| "babel-preset-react": "^6.24.1", | |
| "babel-preset-stage-2": "^6.24.1", | |
| "css-loader": "^0.28.5", | |
| "react": "^15.6.1", | |
| "react-dom": "^15.6.1", | |
| "react-redux": "^5.0.6", | |
| "redux": "^3.7.2", | |
| "redux-infinite-scroll": "^1.0.9", | |
| "redux-thunk": "^2.2.0", | |
| "style-loader": "^0.18.2", | |
| "webpack": "^3.5.5" | |
| }, | |
| "scripts": { | |
| "prod": "webpack -p", | |
| "dev": "webpack -d" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { combineReducers } from 'redux' | |
| import * as actions from './actions.jsx' | |
| export const initialAppState = { | |
| messages1: [], | |
| loadingMore1: false, | |
| messages2: [], | |
| loadingMore2: false | |
| } | |
| const demo = (state = initialAppState, action) => { | |
| if (action.type === actions.PREPARE1) { | |
| return { | |
| ...state, | |
| loadingMore1: true, | |
| } | |
| } else if (action.type === actions.MESSAGE1) { | |
| return { | |
| ...state, | |
| messages1: action.msg, | |
| loadingMore1: false | |
| } | |
| } else if (action.type === actions.PREPARE2) { | |
| return { | |
| ...state, | |
| loadingMore2: true, | |
| } | |
| } else if (action.type === actions.MESSAGE2) { | |
| return { | |
| ...state, | |
| messages2: action.msg, | |
| loadingMore2: false | |
| } | |
| } else { | |
| return state | |
| } | |
| } | |
| const reducer = combineReducers({ | |
| demo | |
| }) | |
| export default reducer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react' | |
| import ReactDOM from 'react-dom'; | |
| import ReduxInfiniteScroll from 'redux-infinite-scroll' | |
| export default class ReduxInfiniteScrollEx extends ReduxInfiniteScroll { | |
| constructor(props) { | |
| super(props) | |
| this._pastLength = 0 | |
| } | |
| componentDidUpdate () { | |
| const currentLength = this._scrollHeight() | |
| if (currentLength > this._pastLength) { | |
| ReactDOM.findDOMNode(this).scrollTop += (currentLength - this._pastLength) | |
| } | |
| if (currentLength !== this._pastLength) { | |
| this._pastLength = currentLength | |
| } | |
| this.attachScrollListener(); | |
| } | |
| _scrollHeight() { | |
| return ReactDOM.findDOMNode(this).scrollHeight | |
| } | |
| _elScrollListener() { | |
| let el = ReactDOM.findDOMNode(this) | |
| if (this.props.horizontal) { | |
| let leftScrollPos = el.scrollLeft | |
| let totalContainerWidth = el.scrollWidth | |
| let containerFixedWidth = el.offsetWidth | |
| let rightScrollPos = leftScrollPos + containerFixedWidth | |
| return (totalContainerWidth - rightScrollPos) | |
| } | |
| return el.scrollTop | |
| } | |
| scrollListener() { | |
| if (this._totalItemsSize() <= 0) return | |
| let bottomPosition = this.props.elementIsScrollable ? this._elScrollListener() : this._windowScrollListener() | |
| if (bottomPosition === 0) { | |
| this.detachScrollListener() | |
| this.props.loadMore() | |
| } | |
| } | |
| render () { | |
| const Holder = this.props.holderType | |
| return ( | |
| <Holder className={ this._assignHolderClass() } style={{height: this.props.containerHeight, overflow: 'scroll'}}> | |
| {this.renderLoader()} | |
| {this.props.animateItems ? this._renderWithTransitions() : this._renderOptions()} | |
| </Holder> | |
| ) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var webpack = require('webpack') | |
| module.exports = { | |
| entry: { | |
| './js/app': './jsx/app.jsx' | |
| }, | |
| output: { | |
| path: __dirname, | |
| filename: '[name].bundle.js' | |
| }, | |
| module: { | |
| loaders: [ | |
| { | |
| test: /\.css$/, | |
| loaders: ['style-loader', 'css-loader?modules'], | |
| }, | |
| { | |
| test: /\.jsx$/, | |
| exclude: /(node_modules|.git)/, | |
| loader: 'babel-loader', | |
| query: { | |
| presets: ['es2015', 'react', 'stage-2'] | |
| } | |
| }, | |
| { | |
| test: /\.js$/, | |
| exclude: /(node_modules|.git)/, | |
| loader: "babel-loader", | |
| query:{ | |
| presets: ['es2015'] | |
| } | |
| } | |
| ] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment