frint-data
Collections in frint-data
do not allow mutations via any default public methods any more. You have to write your own custom methods if you want to change their state.
import { Types, createModel, createCollection } from 'frint-data';
const Todo = createModel({
schema: {
title: Types.string,
},
});
const Todos = createCollection({
model: Todo,
});
After defining, you could change collections directly via public methods like push
:
const todos = new Todos();
todos.push(new Todo({ title: 'First task' }));
Now you need to define custom methods in your Collection if you want to mutate its state:
import { Types, createModel, createCollection } from 'frint-data';
const Todo = createModel({
schema: {
title: Types.string,
},
});
const Todos = createCollection({
model: Todo,
addTodo(todo) {
// `this.push` is only made available INSIDE custom methods
this.push(todo);
},
});
Now from instances:
const todos = new Todos();
// `push` doesn't exist as a public method
typeof todos.push === 'undefined';
// new todo models can only be pushed into the collection via custom method
todos.addTodo(new Todo({ title: 'First task' }));