Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear on constants example in the docs #68

Closed
aidos opened this issue Jan 21, 2015 · 2 comments
Closed

Unclear on constants example in the docs #68

aidos opened this issue Jan 21, 2015 · 2 comments

Comments

@aidos
Copy link
Contributor

aidos commented Jan 21, 2015

http://martyjs.org/guides/constants/index.html contains the following code snippet regarding the second argument to Constants functions:

var UserActionCreators = Marty.createActionCreators({
  deleteUser: UserConstants.DELETE_USER(function (user) {
    this.dispatch(user);
  }, { foo: true })
});
var FooStore = Marty.createStore({
  handlers: {
    fooAction: { foo: true }
  },
  fooAction: function () {
    ...
  }
})

In the example it looks like by suppling a 2nd arg you're changing the signature used to identify the action in the handler registration later. So you can write { foo: true } instead of UserConstants.DELETE_USER.

Is that what's going on and if so, what's the purpose of it?

@jhollingworth
Copy link
Contributor

Hey, good question. The docs need some improvement here which I will look into. In the meantime:

The second argument is the action creator attributes which you can query using an action predicate. These attributes are useful when you want to listen to actions based on something other than their type e.g. if you wanted to listen to all actions that came from the server, you'd pass in { server: true } as the second argument to the creator and { server: true } as the action predicate.

Does that make sense?

Thanks

@aidos
Copy link
Contributor Author

aidos commented Jan 27, 2015

Ok, that does make sense. Thanks.

In terms of the rules. What would happen if you queried using more advanced structures? For example, would {server:true, notification:true} pick up events defined as {server:true} as well as {notification:true}?

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

No branches or pull requests

2 participants