Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jakejarrett/collection
:scream_cat: 450 byte collection inspired by Backbone's Collection
https://github.com/jakejarrett/collection
backbone collection
Last synced: 3 days ago
JSON representation
:scream_cat: 450 byte collection inspired by Backbone's Collection
- Host: GitHub
- URL: https://github.com/jakejarrett/collection
- Owner: jakejarrett
- Created: 2017-06-15T03:14:32.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-07-09T08:42:41.000Z (over 7 years ago)
- Last Synced: 2024-11-02T00:22:33.482Z (about 2 months ago)
- Topics: backbone, collection
- Language: JavaScript
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Collection
* **Tiny** Unminified filesize is ~450 bytes
* **Extensible** Its a small class that you can easily extend with ES6
* **Easy to use** Simply call add / remove for your models
* **Agnostic** Simply works with objects, doesn't have any dependency for any function from each model (You could mix & match models if you needed)## Notice
Be aware, this project is only written for ES6+ clients at the moment.For a list of supported browsers, check the [mdn browser compatability list](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes#Browser_compatibility) for ES6 classes
## API
### ES6
```js
// Import the dependency
import Collection from '@jakejarrett/collection'
import Model from '@jakejarrett/model'const MyModel = new Model({ username: 'jake', id: 0 })
const MyCollection = new Collection([MyModel.freeze()])const models = MyCollection.freeze()
// models contains the Frozen version of MyModel```
## Documentation
### add
The `add` function takes a **Object** parameter.It has no return value.
```js
MyCollection.add({ username: 'jake' })
```### remove
The `remove` value takes an object. It will do a shallow comparison & remove the first similar model / object
It has no return value.
```js
MyCollection.remove({ username: 'jake' })
```### freeze
A simple function that returns a "frozen" version of the Array of models (If you add one, it will not mutate the return value of freeze())```js
MyCollection.add({ username: 'jake' })const divergePoint = MyCollection.freeze()
MyCollection.remove({ username: 'jake' })
// Will fail
divergePoint === MyCollection.freeze()```