forked from gabrielpoca/meteor-redux-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Why: In this version I'm using the package `meteor-ditto`. It's a nice abstraction that implements the system I talk about in the blog post. This also solves the "loading" message, which wasn't working on the previous demo app.
- Loading branch information
1 parent
7f71ae2
commit 547a751
Showing
10 changed files
with
72 additions
and
66 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules/ | ||
node_modules/ | ||
.tern-port |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
Meteor Redux Demo | ||
================= | ||
|
||
This repository contains a demonstration application for the article [A bridge between React and Meteor](https://subvisual.co/blog/posts/79-working-with-meteor-react-and-redux). In this application you can write and see messages. If you try to write an empty message you'll see an error. | ||
This repository contains a demonstration application for the article [A bridge | ||
between React and | ||
Meteor](https://subvisual.co/blog/posts/79-working-with-meteor-react-and-redux). | ||
In this application you can write, remove, and see messages. If you try to write an empty | ||
message you'll see an error. While the messages are loading you see a | ||
"loading" message. | ||
|
||
The purpose of this application is to demonstrate a possible setup for Redux on Meteor, most code written here is not acceptable on production application. | ||
The purpose of this application is to demonstrate a possible setup for Redux on | ||
Meteor, most code written here is not acceptable on production application. | ||
|
||
This application uses the package | ||
[meteor-ditto](https://github.com/gabrielpoca/meteor-ditto). It's a working in | ||
progress implementing the system I talk about in the blog post. |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,29 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
|
||
class MessagesList extends Component { | ||
renderMessage(message, index) { | ||
return <li key={index}>{message.text}</li>; | ||
renderMessage({ _id, text }, index) { | ||
return ( | ||
<li key={index}> | ||
{text} <a href="#" onClick={() => this.props.onRemove(_id)}>Remove</a> | ||
</li> | ||
); | ||
} | ||
|
||
renderLoading() { | ||
return <p>Loading messages...</p>; | ||
} | ||
|
||
render() { | ||
return <ul>{this.props.messages.map(this.renderMessage)}</ul>; | ||
if (!this.props.ready) | ||
return this.renderLoading(); | ||
return <ul>{this.props.messages.map(this.renderMessage.bind(this))}</ul>; | ||
} | ||
} | ||
|
||
MessagesList.propTypes = { | ||
messages: PropTypes.array.isRequired, | ||
onRemove: PropTypes.func.isRequired, | ||
ready: PropTypes.bool, | ||
}; | ||
|
||
export default MessagesList; |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
import { Tracker } from 'meteor/tracker'; | ||
import { createStore, applyMiddleware } from 'redux'; | ||
import { createStore, applyMiddleware, compose } from 'redux'; | ||
import thunk from 'redux-thunk'; | ||
|
||
import { connect as connectCollection } from 'meteor-ditto'; | ||
import reducers from '../reducers/reducers'; | ||
import Messages from '../../lib/messages'; | ||
|
||
export default () => { | ||
const store = createStore(reducers, applyMiddleware(thunk)); | ||
const store = createStore(reducers, compose( | ||
applyMiddleware(thunk), | ||
window.devToolsExtension ? window.devToolsExtension() : fn => fn, | ||
)); | ||
|
||
Tracker.autorun(() => { | ||
store.dispatch({ | ||
type: 'SET_MESSAGES', | ||
messages: Messages.find().fetch(), | ||
}); | ||
}); | ||
connectCollection(Messages, store); | ||
|
||
return store; | ||
}; |
This file contains 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
This file contains 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