https://github.com/arillo/meteor-astronomy-softremove-behavior
Softremove behavior for Meteor Astronomy
https://github.com/arillo/meteor-astronomy-softremove-behavior
Last synced: 2 months ago
JSON representation
Softremove behavior for Meteor Astronomy
- Host: GitHub
- URL: https://github.com/arillo/meteor-astronomy-softremove-behavior
- Owner: arillo
- License: mit
- Created: 2015-05-19T17:30:22.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-05-27T07:46:59.000Z (about 11 years ago)
- Last Synced: 2025-12-25T22:34:28.556Z (6 months ago)
- Language: JavaScript
- Size: 105 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Meteor Astronomy softremove behavior
## About
This behavior adds to fields to the schema `removed` and `removedAt`. `removed` will be a boolean marked true and `removedAt` will be filled with the current date on document remove. If you want to softremove an element just call softRemove() instead of remove()
## Usage
```js
var post = new Post();
post.softRemove();
console.log(post.removed); // Prints out true if removed
console.log(post.removedAt); // Prints out date of document removable
```
You can also pass options for the removed and removedAt fields
```js
Post = Astronomy.Class({
name: 'Post',
collection: Posts,
fields: ['title'],
behaviors: {
'softremove': {
removedFieldName: 'deleted',
removedAtFieldName: 'deletedAt'
}
}
});
```
## Events
You will get two events, one before ```beforesoftremove``` and one after ```aftersoftremove``` the object has been softremoved.
**Notice:** currently you have to take care yourself of removing the softRemoved objects from your publish functions. You can do this by filtering via removed: false, like:
```js
Meteor.publish( 'posts', function() {
Posts.find({},{removed: false});
}
```
**TODO:**
- Implement retrieval of query selector to omit removed items