React + Flux
and the future of e-commerce search
by
Ken Ding and Sean Kozer
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)
What we do
- Retail eCommerce across multiple departments
- Django + Backbone + more
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)
Let's Build Something
- Elasticsearch is great, but our front end is lacking
- Heaps of view logic makes it complex
- Only way out is to overhaul
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)
Why React?
- Opportunity to build a prototype
- New way of thinking
- Easy for collaboration
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)
What is React?
- Javascript library for creating UI
- Just the V in MVC
- Built by Facebook and Instagram
What is FLUX?
- Design pattern
- Unidirectional flow
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)
Initial "React"ion
Mark up in JS?
No thanks.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)
Technical benefits
- Building components, not templates.
- Reduced complexity
- Declarative
- Goodbye micromanaging DOM manipulation
- Figuring out which views to update
- Virtual DOM
- Fun
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)
Example of DOM MANIPULATION
var View = Backbone.View.extend({
modifyDOM: function() {
this.$el.html(this.template(obj));
},
render: function() {
this.$el.html(this.template(obj));
return this;
}
});
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)
DEMO TIME
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)
How we built it
Tech Stack
- ReactJS + Flux + Immutable JS
- Webpack
- Go
- Elasticsearch
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)
Component Hierarchy
![](https://s3-ap-southeast-2.amazonaws.com/uploads-au.hipchat.com/41288/1121758/oPMLYlKGWPUBB6o/Component_Hierarchy_Simple_Edited.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)
Component Hierarchy
![](https://s3-ap-southeast-2.amazonaws.com/uploads-au.hipchat.com/41288/1121758/10hr0jw6Mq6dfbt/Component%20Hierarchy.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)
Component Hierarchy
/** @jsx React.DOM */
var React = require('react');
var MainApp = React.createClass({
render: function() {
return (
<div>
<InstantBar />
<InfoBox />
<ProductGrid />
</div>
);
}
});
module.exports = MainApp;
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)
The Flux Cycle
![](https://github.com/facebook/flux/raw/master/docs/img/flux-diagram-white-background.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)
The Flux Cycle
![](https://s3-ap-southeast-2.amazonaws.com/uploads-au.hipchat.com/41288/1121758/iBAQHulW0c58wzi/Flux%20Diagram.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)
The Flux Cycle
![](https://s3-ap-southeast-2.amazonaws.com/uploads-au.hipchat.com/41288/1121758/AlqEjXS0GuFmKjn/Flux%20Diagram%202.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)
The Flux Cycle
var SuggestionActionCreator = {
fetchSelectedProduct: function (text) {
// Making a call to our server
ProductWebAPIUtils.fetchProducts(text)
.then(function (data, textStatus, jqXHR) {
AppDispatcher.dispatch({
actionType: Constants.FETCH_PRODUCTS,
data: data
});
}, function (jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
});
}
}
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)
Lessons
- Hard to choose the right implementation
- Flux
- Reflux
- Fluxxor
- Building components from scratch
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)
Questions?
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)
We're hiring
check out
careers.kogan.com/software-devs-engineering
![](https://s3.amazonaws.com/media-p.slid.es/uploads/skozer/images/1131546/kogan.com-Logo_BW.png)