Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
Update examples to reflect new file structure and to use external soc…
Browse files Browse the repository at this point in the history
…ket IO and localDB libraries
  • Loading branch information
eitak committed Jun 5, 2016
1 parent acd9d2d commit c50f94e
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 31 deletions.
14 changes: 8 additions & 6 deletions examples/counter/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "redux-live-counter-example",
"version": "0.0.4",
"version": "0.0.5",
"description": "Redux Live counter example",
"scripts": {
"clean": "rm -rf build",
"compile": "npm run compile:server && npm run compile:shared && npm run compile:client",
"compile:server": "babel src/server -d build/server",
"compile:shared": "babel src/shared -d build/shared",
"compile:client": "mkdir -p build/client && browserify src/client/index.js -t babelify -o build/client/bundle.js",
"build": "npm run build:server && npm run build:shared && npm run build:client",
"build:server": "babel src/server -d build/server",
"build:shared": "babel src/shared -d build/shared",
"build:client": "mkdir -p build/client && browserify src/client/index.js -t babelify -o build/client/bundle.js",
"start": "node build/server/index"
},
"repository": {
Expand All @@ -27,7 +27,9 @@
"react-dom": "^15.1.0",
"react-redux": "^4.4.5",
"redux": "^3.5.2",
"redux-live": "0.0.3"
"redux-live": "0.0.5",
"redux-live-socketio": "0.0.1",
"redux-live-localdb": "0.0.1"
},
"devDependencies": {
"babel-cli": "^6.9.0",
Expand Down
6 changes: 3 additions & 3 deletions examples/counter/src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import {render} from 'react-dom'
import {Provider} from 'react-redux'
import {createStore, applyMiddleware, combineReducers} from 'redux'

import SocketIoServerCommunicator from 'redux-live/lib/client/server-communicator/SocketIoServerCommunicator'
import {createReduxLiveMiddleware, reduxLiveReducer} from 'redux-live/lib/client'
import ServerCommunicator from 'redux-live-socketio/ServerCommunicator'
import {createReduxLiveMiddleware, reduxLiveReducer} from 'redux-live/client'

import Counter from './components/Counter'
import counter from '../shared/reducers/index'

require("babel-polyfill");

const serverCommunicator = new SocketIoServerCommunicator();
const serverCommunicator = new ServerCommunicator();
const reduxLiveMiddleware = createReduxLiveMiddleware(serverCommunicator);

const initialState = {
Expand Down
8 changes: 4 additions & 4 deletions examples/counter/src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import http from 'http'
import path from 'path'
import {createStore, applyMiddleware} from 'redux'

import LocalDb from 'redux-live/lib/server/db/LocalDb'
import SocketIoClientCommunicator from 'redux-live/lib/server/client-communicator/SocketIoClientCommunicator'
import ReduxLiveServer from 'redux-live/lib/server'
import LocalDb from 'redux-live-localdb'
import ClientCommunicator from 'redux-live-socketio/ClientCommunicator'
import {ReduxLiveServer} from 'redux-live/server'

import counter from '../shared/reducers/index'

Expand Down Expand Up @@ -44,7 +44,7 @@ app.get('/', (req, res) => {
*/
const db = new LocalDb();
db.createStream('counter', {value: 0});
const clientCommunicator = new SocketIoClientCommunicator(server);
const clientCommunicator = new ClientCommunicator(server);

const reduxLiveServer = new ReduxLiveServer({reducer: counter, db, clientCommunicator});

Expand Down
14 changes: 8 additions & 6 deletions examples/shopping-cart/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "redux-live-shopping-cart-example",
"version": "0.0.4",
"version": "0.0.5",
"description": "Redux Live shopping cart example",
"scripts": {
"compile": "npm run compile:server && npm run compile:shared && npm run compile:client",
"compile:server": "babel src/server -d build/server",
"compile:shared": "babel src/shared -d build/shared",
"compile:client": "mkdir -p build/client && browserify src/client/index.js -t babelify -o build/client/bundle.js",
"build": "npm run build:server && npm run build:shared && npm run build:client",
"build:server": "babel src/server -d build/server",
"build:shared": "babel src/shared -d build/shared",
"build:client": "mkdir -p build/client && browserify src/client/index.js -t babelify -o build/client/bundle.js",
"start": "node build/server/index"
},
"repository": {
Expand All @@ -27,7 +27,9 @@
"react-dom": "^15.1.0",
"react-redux": "^4.4.5",
"redux": "^3.5.2",
"redux-live": "0.0.3"
"redux-live": "0.0.5",
"redux-live-socketio": "0.0.1",
"redux-live-localdb": "0.0.1"
},
"devDependencies": {
"babel-cli": "^6.9.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, {Component, PropTypes} from 'react'
import {connect} from 'react-redux'

import {addToCart} from '../actions'
import ProductItem from '../components/ProductItem'
import ProductsList from '../components/ProductsList'
Expand Down
6 changes: 3 additions & 3 deletions examples/shopping-cart/src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import {render} from 'react-dom'
import {createStore, applyMiddleware, combineReducers} from 'redux'
import {Provider} from 'react-redux'

import SocketIoServerCommunicator from 'redux-live/lib/client/server-communicator/SocketIoServerCommunicator'
import {createReduxLiveMiddleware, reduxLiveReducer} from 'redux-live/lib/client'
import ServerCommunicator from 'redux-live-socketio/ServerCommunicator'
import {createReduxLiveMiddleware, reduxLiveReducer} from 'redux-live/client'

import App from './containers/App'
import {cart, products} from '../shared/reducers'
import subscribeProductsMiddleware from './middleware/subscribeProductsMiddleware'

require("babel-polyfill");

const serverCommunicator = new SocketIoServerCommunicator();
const serverCommunicator = new ServerCommunicator();
const reduxLiveMiddleware = createReduxLiveMiddleware(serverCommunicator);

const initialState = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import {SET_STREAM_INITIAL_STATE, SUBSCRIBE_TO_STREAM} from 'redux-live/lib/shared/constants/ActionTypes'
import {ReduxLiveActionTypes} from 'redux-live/shared'

const subscribeProductsMiddleware = store => next => action => {
const containsProducts = action.type === SET_STREAM_INITIAL_STATE
const containsProducts = action.type === ReduxLiveActionTypes.SET_STREAM_INITIAL_STATE
&& action.reduxLive.streamId.topic === 'all-products';
if (containsProducts) {
action.state.productIds.forEach(productId => {
const subscribeToProductAction = {type: SUBSCRIBE_TO_STREAM, streamId: {topic: 'products', id: productId}};
const subscribeToProductAction = {
type: ReduxLiveActionTypes.SUBSCRIBE_TO_STREAM,
streamId: {topic: 'products', id: productId}
};
store.dispatch(subscribeToProductAction)
})
}
Expand Down
12 changes: 6 additions & 6 deletions examples/shopping-cart/src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import _ from 'lodash'
import {createStore, applyMiddleware} from 'redux'
import uuid from 'node-uuid'

import LocalDb from 'redux-live/lib/server/db/LocalDb'
import SocketIoClientCommunicator from 'redux-live/lib/server/client-communicator/SocketIoClientCommunicator'
import ReduxLiveServer from 'redux-live/lib/server'
import {SUBSCRIBE_TO_STREAM} from 'redux-live/lib/shared/constants/ActionTypes'
import LocalDb from 'redux-live-localdb'
import ClientCommunicator from 'redux-live-socketio/ClientCommunicator'
import {ReduxLiveServer} from 'redux-live/server'
import {ReduxLiveActionTypes} from 'redux-live/shared'

import {cart, product} from '../shared/reducers/index'
import createCart from './createCart'
Expand Down Expand Up @@ -58,7 +58,7 @@ db.createStream({topic: 'products', id: 'product-3'}, {
"inventory": 5
});

const clientCommunicator = new SocketIoClientCommunicator(server, streamId => streamId.topic + '/' + streamId.id);
const clientCommunicator = new ClientCommunicator(server, streamId => streamId.topic + '/' + streamId.id);

const reduxLiveServer = new ReduxLiveServer({
getReducer: streamId => {
Expand All @@ -72,7 +72,7 @@ clientCommunicator.onNewClient(clientId => {
const cartId = uuid.v4();
createCart(reduxLiveServer, cartId);
clientCommunicator.sendActionToClient(clientId, {
type: SUBSCRIBE_TO_STREAM,
type: ReduxLiveActionTypes.SUBSCRIBE_TO_STREAM,
streamId: {
topic: 'carts',
id: cartId
Expand Down

0 comments on commit c50f94e

Please sign in to comment.