Comments (16)
Check it out
from todos.
It seems like this would be super hard to implement correctly in general, since you need to parse the update modifier. Is there a way to do it somehow so that it doesn't involve writing a ton of code for all the different cases of update
?
from todos.
Yeah, it's kind of the same problem as allow/deny.
I'm not really sure what the best approach is.
Would the following logic work?:
const targetModifier = {};
const changingMods = _.each(modifier, (changes, mod) => {
if (_.has(changes, 'userId')) {
targetModifier[mod] = {userId: changes[userId]};
}
});
That would work for the $set
and $unset
cases anyway. Probably weird edge cases around $push
& friends though.
An alternative would be to look at the source document after the update. I think the trick there is to detect if the field changes without doing unnecessary lookups.
from todos.
Would it maybe be OK to do one more lookup for each insert that does denormalization?
from todos.
If that's possible? This is on an update to the source collection -- I don't think we want to do an unnecessary lookup if we can help it -- so we'd want to figure out from the modifier
if a look up is necessary -- which is kind of an easier version of the original problem..
from todos.
Hmm.. I feel like analyzing update operators is like the opposite of how I'd rather be spending my time.
Is it really that bad to just do the denormalization in the methods directly rather than inside update
? Perhaps there's a way to just warn people if they forgot to do denormalization, or test it easily, or something?
from todos.
Yeah the problem with putting it in methods is that it's spread all over the place. But maybe an intermediate solution is for the method to call Denormalizer.update(...)
or something?
from todos.
Yeah and it could perhaps pass the new value of the field, since that will be clear from the method body.
from todos.
This works for me as a solution for now anyway. Want me to change it?
from todos.
yeah, although I'm not sure if Denormalizer.update
is the right thing? Is it like Denormalizer.<method name>
?
from todos.
Oh, so what I meant was something like
Lists.methods.makePrivate = new Method({
run({ listId }) {
...
Lists.update(listId, {
$set: { userId: this.userId }
});
Lists.userIdDenormalizer.set(listId, this.userId);
}
});
from todos.
(An conceivably if another method set the userId
on a list, it would also call Lists.userIdDenormalizer.set
from todos.
Yeah that looks awesome.
from todos.
So I guess the burden on the developer would be:
- Whenever you write a new method, check to see if any denormalizers need to be added
- Whenever you add a new denormalizer, check all of the methods to see if you need to add it there
Shouldn't be too bad, I think?
from todos.
Yeah. I mean it's not as nice as putting it on the mutator, but it's not bad. And if someone makes a bulletproof denormalizer package, then I guess we can go back to it.
from todos.
The method pattern means at least you know where to look!
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.