Developing in MapStore 2
ES6 Functionalities
React
Redux
MapStore 2
FRONT END EVOLVES
JAVASCRIPT EVOLVES WITH IT
MapStore 2
Let’s see all of them:
ES6 - Arrow Function
( ) => { /* some code */} // function without arguments
argument => value // one argument don’t need (), implicit return
argument => ({object: “to return”}) // return an object - use ({}) (not function body)
(arg1, arg2) => { return arg1 + arg2; } // more
() => this.fun() // this is the one in the definition scope
ES6 Variable declaration
const a = “MY_CONST”; // cannot be re-assigned new content, static check
let a = “myvar” // block scoped var (var was function scope)
ES6 spread operator
var params = [3,4]
var other = [ 1, 2, ...params ] // Spread operator for arrays, result ->[1,2,3,4]
const obj = { a: “a”, b: “b”}; const d=”d”;
const newObj = { ...obj, c: “c”, d}; // Spread operator for objects
// newObj = { a: “a”, b: “b”,c: “c”, d: “d”}
ES6 Destructuring
var other = [1,2,3,4]
var [a, ,b] = other; // array destructuring a =1, b=3
-----
var object = { A: “A”, B: “B”, C:”C”};
var {A, B} = object; // object destructuring. A= “A” , B= ”B”
ES6 Default Value - Rest operators
(x = 42) => x // default values for function parameter
obj = { a: “a”, b: “b”, c: “c”}
var {a, ...other} = obj; // rest operator for objects other= {b:”b”, c:”c”}, a=”a”
//… for functions
fun = function(a, ...b) {return b;} // rest parameter (array of last parameters)
ES6 Array map reduce filter
[1,2,3].map(a => a +1) // [2,3,4]
[1,2,3].filter(a => a > 1) // [2,3]
reduce( (accumulator, current) => nextAccumulatorValue, initialAccValue)
Composition: [1,2,3].map( a => a + 1 ).filter(a => a > 1 ).reduce( (a,b) => a+b, 0)
ES6 - Promises
Pipeline of callbacks
React
A javascript library for building user interfaces
Flux
APPLICATION ARCHITECTURE FOR BUILDING USER INTERFACES
Redux
Predictable state container for JavaScript apps.
React-Redux
Official React bindings for Redux:
Redux Middlewares - Thunk
Write action creators that return a function instead of an action. The thunk can be used to delay the dispatch of an action, or to dispatch only if a certain condition is met. The inner function receives the store methods dispatch and getState as parameters.
Redux Middlewares - Redux Observable
Compose and cancel async actions to create side effects and more.
MapStore 2
MapStore 2
Project Structure
web/client contains front-end (javascript)
Pages (managed by react-router) + some plugins are also plugins containers
Most of the times you don’t care about it.
You have only to develop your own plugins
MapStore 2 - Develop a plugin
If you want to use other plugin containers (Toolbar), configure it properly. (Each container has its own props to configure)
Then you have to :
Resources