Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save notakaos/7b049bdec211f20e283a to your computer and use it in GitHub Desktop.
Save notakaos/7b049bdec211f20e283a to your computer and use it in GitHub Desktop.
Meteor 1.3 + React Simple Memo Step 5-3
// 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;
}
// 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