Releases: codeship/modelist
v0.9.1
Types
This release marks a first exciting step into a new and better direction for Modelist. The main src files have all been updated to use typescript, and along the path, some things got improved, updated or fixed.
Overall this might not be the most exciting release feature-wise, but this was an important step to make before Modelist will be extended. I am looking into providing a well-written definition file as a patch asap. (Still learning 🤷♂️ ).
There is one interesting change that should not break anyone's application, but here we go:
Removed convert option:
In the configuration of a new Model, there was the convert option that needed to be set to true if basic values should be updated to objects when record was called.
Actually, this does not make a lot of sense, because you can use almost nothing that Modelist brings along if the record would be a single value.
Now all simple values will now be converted to an object by default with the primaryKey added!
model.record(...[1, 'fred'])
model.all() // [{ id: uuid(), value: 1 }, { id: uuid(), value: 'fred' }]Thanks,
Roman
Inception
So far 0.7.0 marks the most important release of Modelist so far.
Why? I was able to add my first user-requested feature #1 to add model.validate support to be called from outside. Also, I tackled some shortcomings that arose from working with Modelist in production with my colleagues. Those important additions are added now as well. I basically had to rework the instance structure and how it all comes together to support the upgrade filters.
Details:
- validate() method - A validate method can now be called and will validate against the passed in schema.
- last() - A handy companion to the
first()method, and will give you the last element of the collection. - has(key) - You can now check if an element exists in the collection using
hasand passing in the primaryKey. Works likefindbut will return aBoolean
Drumroll please 🥁
- filters - Filters passed in to the instance will no longer just return the filtered array, but a new
Modelinstance giving you access to everything the core of Modelist supports.
Here is a short example:
const model = new Model({
data: [
{ id: 1, task: 'Buy Milk', done: false },
{ id: 2, task: 'Update Modelist', done: true },
],
filters: {
completed: c => c.filter(e => e.done)
}
})
model.completed.size // = 1
model.completed.all() // [{ id: 2, task: 'Update Modelist', done: true }]
model.completed.first() // [{ id: 2, task: 'Update Modelist', done: true }]
// ... and all the other stuff you lovev0.6.0
This version extends Modelist we two new functionalities:
A new findBy method:
findBy can be used on the model to find an element based on custom key. If you need to find a element based on it's name value you can now use: model.findBy('name', 'Jane Doe') and you'll receive the found Entry Object.
Customize the Model with filters:
When instantiating a new Model, you can now pass in a filters object. The filters object should be a list of functions that return a subset of all available entries. The functions get the collection passed in, and up you go.
Here's an example:
const tasks = new Model({
data: [
{task: 'Go for a walk', done: false},
{task: 'Buy Milk', done: true},
{taks: 'Feed the cat', done: true}
],
filters: {
completed: (c) => c.filter(t => t.done === true)
}
})
console.log(tasks.completed.length) //= 2Best,
Roman