Comments (11)
I'm not a fan of autovalue after working with it for a while - personally I would prefer using SS only for schema validation?
from todos.
I'm inclined to agree TBH.
I think the way to do something like an autovalue more explicitly is to subclass the (say) update
function and do it there. So you'd do
class ListsCollection extends Collection2 {
update(query, mod) {
mod.$set.updatedAt = new Date();
super(query, mod);
}
}
What do you think @stubailo? Also, are you ok with default values?
from todos.
Hmm... perhaps for something like that, yes. For default values I'd prefer to just have them in the insert
method.
from todos.
Oh, sorry that was two questions.
So question 1. was do you think the "subclassing" approach to replace autovalue is correct (the alternative is to put that logic in every method body which is gross).
Question two is around default values -- so I guess I mean do we want to put:
A) default values in the schema
B) default values in the insert
method, ala the above
I prefer A) for simple stuff like defaultValue: false
.
from todos.
- I feel like overriding update will be super duper hard - like, the example you gave is super simple, but how are you going to ensure other things? Update operators are hella complex.
- Default values in the schema make sense, but the issue is that
autoValue
isn't a default value - it's actually run on all updates as well. I wish there were something likeautoValue
but that only ran oninsert
.
from todos.
Re update operators --
I'm not saying you allow arbitrary updates. Everything still goes through a method that you tightly control. It's just that it makes sense to do completely common stuff (like updatedAt
as a canonical example) in one place.
from todos.
Let's look at an example - say you want to make sure that a certain field is always denormalized - for example, you want to make sure that fullName = firstName + lastName
. How would you do that by overriding update
?
from todos.
I think it's tricky. In that case, if there was a single method that updated firstName
or lastName
, perhaps you'd do it in the method body?
Alternatively, if you knew that you were only going to $set
in update()
(and you enforced that), then you could do it there.
I can see that there's an issue about deciding where to put it.
from todos.
Ok, based on our denormalizer discussion, we will make any "hooks" that are based on the shape of the modifier happen at the method level. Perhaps someone will write an awesome package that fully understands mongo operators and we can move it back to the mutator[1]
Another possibility that's more in line with our approach in the past would be to add a mutator to the collection called something like:
setOnSingle(id, attributes) {
check(id, String); // i.e. enforce a single document
this.update(id, {$set: attributes});
// now I can do denormalizations with a lot more confidence
}
When you know that
a) it's only one doc
b) it's always a $set
You can actually do it without needing to be too clever (at least if you don't support dotted operators).
[1] Maybe minimongo is this package somehow (using LocalCollection._modify
). But I think it's tricky in general with esoteric operators like $addToSet
, and updates that may affect more than one document.
from todos.
See #42
from todos.
I think the final two points can be left for now and just remain on the guide code issues list
from todos.
Related Issues (20)
- Apollo branch needs to be updated to reflect current Apollo project. HOT 5
- Any interest in a Vue port? HOT 17
- Cannot serve the built app through an ad-hoc local network
- Update React Todo to use TypeScript since PropTypes deprecation HOT 1
- replace createContainer with withTracker HOT 1
- CSS Import?
- http://todos.mysite.com redirect to https://todos.mysite.com HOT 1
- Current version won't start (last commit 59f6621 on 27 Apr 2017) HOT 1
- Add Server Side Rendering and Dynamic Imports to React To Dos HOT 1
- Why are collections not imported or defined in the register-api / api.js file ? Where are they imported and defined? HOT 3
- Where are collections defined and imported? HOT 1
- Why the code looks so messy? HOT 2
- ant-design branch ready to pull HOT 2
- Uncaught Error: Target container is not a DOM element. HOT 6
- Error Connection Websocket
- Cannot find sockjs HOT 1
- React branch update with hooks - New react/typescript branch? HOT 5
- todos example doesn't run, error in meteor npm i
- german language HOT 1
- Official Example doesn't update to latest version 1.11.x HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from todos.