Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Easy method delegation for action handlers #12

Open
sobrinho opened this issue Nov 1, 2015 · 3 comments
Open

Easy method delegation for action handlers #12

sobrinho opened this issue Nov 1, 2015 · 3 comments

Comments

@sobrinho
Copy link
Member

sobrinho commented Nov 1, 2015

I'm implementing action handlers as classes, example:

class CommentsActions {
  constructor (comments) {
    this.comments = comments;
  }

  markAsPublished (id) {
    this.comments.markAsPublished(id);
  }

  markAsDraft (id) {
    this.comments.markAsDraft(id);
  }
}

This is a superfluous example but the point is that the almost all methods are delegates to the store.

I'm thinking in having something like rails' delegate to reduce the boilerplate:

import Action from "fluxo";

class CommentsActions extends Action {
  constructor (comments) {
    this.comments = comments;
  }
}

CommentsActions.delegates = {
  comments: ["markAsPublished", "markAsDraft"]
};

You can see that delegates is generic and not related to the store itself, we could be delegating any method to any object.

What you think?

@samuelsimoes
Copy link
Collaborator

I like this, but as I mentioned on #13 I'm seeing Fluxo as just a "state manager", actions handlers and things like this "don't belong" to this package scope. Of course it's a ongoing discussion, here and on the other issue.

I see a better future creating a separate package for this action handler base (no problem if it'll be related to Fluxo), even if it's a small package.

@sobrinho
Copy link
Member Author

sobrinho commented Nov 2, 2015

Partially agree because it would increase the friction to start since we already need two packages.

We can make a meta package like rspec and rails does, fluxo would be a package which simply depends on fluxo-store, fluxo-react-connect-stores, fluxo-action.

@samuelsimoes
Copy link
Collaborator

Good, I like (the meta packaged idea). We can starts it soon (if you want start, no problem for me).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants