Created
March 25, 2016 17:30
-
-
Save notakaos/7b049bdec211f20e283a to your computer and use it in GitHub Desktop.
Meteor 1.3 + React Simple Memo Step 5-3
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
// imports/api/memos/memos.js | |
import { Mongo } from 'meteor/mongo'; | |
class MemosCollection extends Mongo.Collection { | |
insert(doc, callback) { | |
doc.createdAt = doc.createdAt || new Date(); | |
const result = super.insert(doc, callback); | |
return result; | |
} | |
} | |
export const Memos = new MemosCollection('Memos'); | |
// for debug | |
if (Meteor.isDevelopment) { | |
global.collections = global.collections || {}; | |
global.collections.Memos = Memos; | |
} |
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
// imports/ui/containers/AppContainer.js | |
import AppLayout from '../layouts/AppLayout'; | |
import { Memos } from '../../api/memos/memos'; | |
import { createContainer } from 'meteor/react-meteor-data'; | |
const createMemo = content => { | |
Memos.insert({content}); | |
}; | |
const removeMemo = memoId => { | |
Memos.remove({_id: memoId}); | |
}; | |
export default createContainer(() => { | |
return { | |
memos: Memos.find({}, {sort: {createdAt: -1}}).fetch(), | |
createMemo, | |
removeMemo, | |
}; | |
}, AppLayout); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment