Update docs for update action
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 61
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
I think that it's not clear how to update a model if you don't have the properties fetched.
the most common use case is that you get an object with values that you want to update the model with. And the first instinct based on the docs is to do:
const data = {
id: 1,
companyId: 2,
name: 'Olympia Pearson',
birthDate: new Date('1982-08-20 00:00'),
};
const employee = new Employee(data, false);
employee.save();
But if you want to update the model with all the properties you have to do:
const employee = new Employee({}, false);
Object.assign(employee, data);
employee.save();
and for that reason I would add a set method:
/**
* @param {Object} [props={}] Properties to assign to object
* @returns {ModelBase} ModelBase
*/
set(props = {}) {
return Object.assign(this, props);
}
So it can be called like this:
new Employee({}, false).set(data).save();
it would be a good thing also to explain in the docs the lifecycle of oldProps, and when they become just props, the concept is clear if you look through the code and tests, but not on a first glance.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the documented model-construction and save examples, then read the ModelBase behavior and existing tests around oldProps and props. Done means the update workflow and property lifecycle are clear in the docs, with the proposed set method and its chained usage covered if the API change is accepted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100