A simple twitteresque publishing library
brewhk:simple-post
provides a SimplePost
object containing functions you'd need to add, edit, delete and read posts. It also publishes the SimplePosts
collection for you to do more sophisticated queries with.
Every SimplePost document follows the following schema.
Property Name | Type | Mandatory |
---|---|---|
content | String | Yes |
author | String | Yes |
deletedAt | Number | No |
First, add the package from Atmosphere.
meteor add brewhk:simple-post
SimplePost.addPost(postContent, callback)
Callback is called with two objects - error
and result
. result
will be the _id
of the post document.
SimplePost.editPost(id, newPostContent, callback)
Callback is called with two objects - error
and result
. result
will be 1
on success, 0
if no document matched.
There are two ways to retrieve posts - using Meteor methods or using subscription / publication.
SimplePost.getPost(id, callback) // id is the _id of the SimplePost
Callback is called with two objects - error
and result
. result
will be the SimplePost document on success, or undefined
if no document matched.
SimplePost.getPosts(ids, callback) // `ids` is an array of SimplePost _id
SimplePost.getPostsByAuthor(author, callback) // author is _id of the author
SimplePost.getAllPosts(callback)
Callback is called with two objects - error
and result
. result
will be an array of matched SimplePost documents on success, or an empty array if no document matched.
brewhk:simple-post
provides the SimplePosts
collection which you can subscribe to. Using subscription gives you more control over when the data is retrieved, and may allows you to perform more complex operations client-side.
brewhk:simple-post
provides the following subscriptions, which serves identical functions to the methods above:
simplePost(id)
simplePosts(ids)
simplePostsByAuthor(author)
simplePostsAll()
brewhk:simple-post
performs soft-deletes.
SimplePost.deletePost(id, callback)
Callback is called with two objects - error
and result
. result
will be 1
on success, 0
if no document matched.
You can override default values by providing these environment variables.
SIMPLE_POST_MAX_LENGTH
- Set the maximum length for each post, defaults to200
ALLOW_GET_ALL_POSTS
- Set whether you'd allow clients to fetch or subscribe to all posts data (i.e. useSimplePost.getAllPosts(callback)
orMeteor.subscribe('simplePostsAll')
), defaults tofalse