The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Flux Architecture: Application Actions

Flux Architecture: Application Actions

3:25
In this lesson we'll build our actions which will be sent to our dispatcher.
Watch this lesson now
Avatar
egghead.io

In this lesson we'll build our actions which will be sent to our dispatcher.

Avatar
mahesh

What do .bind(null,"xxxxxxx') do ? . Why do we need to bind it ?

In reply to egghead.io
Avatar
Joel

What do .bind(null,"xxxxxxx') do ? . Why do we need to bind it ?

You can check out this lesson for some details on binding functions in JavaScript.

In reply to mahesh
Avatar
Jacob

This got me too. Here is a good link: http://stackoverflow.com/questions/27654149/function-prototype-bind-with-null-as-argument

Basically, it makes a new function in the global scope (hence the null) and the "xxxxxx" would be the first parameter. It's syntactic sugar.

In reply to mahesh
Avatar
Keir Beckett

What does the 'action' parameter get passed in the 'flux.dispatcher' function?

Avatar
Joseph

It represents a typo. :)
dispatcher takes a single argument called payload. While having action and actionType (or other) fields in that payload can be useful in a larger application it is not used in this series. Expect an update to the dispatcher lesson to resolve any confusion.

In reply to Keir Beckett
Avatar
Homan

In app-actions why is dispatch function called with curly braces?

addItem( item ){
dispatch({
actionType: AppConstants.ADDITEM, item
})
},
why isn't it simply called with 2 arguments? If using named parameters and passing an object, why doesn't the second parameter have a key as well? like: {actionType: AppConstants.ADD
ITEM, item: item } ?

Avatar
Shawn

Following with what Joe mentioned, as of this reply there is a typo in the file app-dispatcher.js. The dispatch() function definition is meant to accept one object (named payload) as an argument (Facebook Flux API guide). This payload object (for this application so far) has 2 properties: actionType and item. In app-actions.js, the curly braces surrounding actionType and item indicate that dispatch() is being passed an object literal (for the payload). The 2nd property "item", is using es6 object property shorthand notation.

To clear this up, go to app-dispatcher.js and replace the exported dispatch function with:
export function dispatch( payload ) {
console.log(payload);
flux.dispatch( payload );
}

In reply to Homan
Avatar
Daniel Cortes

So why are you not getting an Uncaught ReferenceError: item is not defined?

In reply to egghead.io
Avatar
rajeshkw

import Dispatcher from 'flux';
const flux = new Dispatcher(); //constructor error for flux 3.0

i had to use below instead..
import Flux from 'flux';
export default new Flux.Dispatcher;

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?