Coder Social home page Coder Social logo

Comments (16)

tmeasday avatar tmeasday commented on June 21, 2024

Check it out

from todos.

stubailo avatar stubailo commented on June 21, 2024

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.

tmeasday avatar tmeasday commented on June 21, 2024

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.

stubailo avatar stubailo commented on June 21, 2024

Would it maybe be OK to do one more lookup for each insert that does denormalization?

from todos.

tmeasday avatar tmeasday commented on June 21, 2024

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.

stubailo avatar stubailo commented on June 21, 2024

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.

tmeasday avatar tmeasday commented on June 21, 2024

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.

stubailo avatar stubailo commented on June 21, 2024

Yeah and it could perhaps pass the new value of the field, since that will be clear from the method body.

from todos.

tmeasday avatar tmeasday commented on June 21, 2024

This works for me as a solution for now anyway. Want me to change it?

from todos.

stubailo avatar stubailo commented on June 21, 2024

yeah, although I'm not sure if Denormalizer.update is the right thing? Is it like Denormalizer.<method name>?

from todos.

tmeasday avatar tmeasday commented on June 21, 2024

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.

tmeasday avatar tmeasday commented on June 21, 2024

(An conceivably if another method set the userId on a list, it would also call Lists.userIdDenormalizer.set

from todos.

stubailo avatar stubailo commented on June 21, 2024

Yeah that looks awesome.

from todos.

stubailo avatar stubailo commented on June 21, 2024

So I guess the burden on the developer would be:

  1. Whenever you write a new method, check to see if any denormalizers need to be added
  2. 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.

tmeasday avatar tmeasday commented on June 21, 2024

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.

tmeasday avatar tmeasday commented on June 21, 2024

The method pattern means at least you know where to look!

from todos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.