Less boilerplate when create a new reducer on Redux
Method:
'use strict'
const createReducer = (initialState, actionHandlers) => {
import React from 'react'; | |
const MIN_SCALE = 1; | |
const MAX_SCALE = 4; | |
const SETTLE_RANGE = 0.001; | |
const ADDITIONAL_LIMIT = 0.2; | |
const DOUBLE_TAP_THRESHOLD = 300; | |
const ANIMATION_SPEED = 0.04; | |
const RESET_ANIMATION_SPEED = 0.08; | |
const INITIAL_X = 0; |
<Ratio width={Ratio.OPTIONS.FLUID} x={3} y={4}> | |
{(width, height) => ( | |
<Chart id={this.props.id} width={width} height={height} /> | |
)} | |
</Ratio> |
/** | |
* Safari 10.1 supports modules, but does not support the `nomodule` attribute - it will | |
* load <script nomodule> anyway. This snippet solve this problem, but only for script | |
* tags that load external code, e.g.: <script nomodule src="nomodule.js"></script> | |
* | |
* Again: this will **not** prevent inline script, e.g.: | |
* <script nomodule>alert('no modules');</script>. | |
* | |
* This workaround is possible because Safari supports the non-standard 'beforeload' event. | |
* This allows us to trap the module and nomodule load. |
[10:39 AM] infected mushroom: Is this analogy correct?
Can we say that the store in the Redux app is like a database?
mapStateToProps
is used to retrive (read) the information from the database where as
mapDispatchToPropsis used to write the information in the same database?
[10:59 AM] infected mushroom: Okay, I am confused now
On official docs it says
Actions are payloads of information that send data from your application to your store
"A phantom type is a parametrised type whose parameters do not all appear on the right-hand side of its definition..." Haskell Wiki, PhantomType
The following write-up is intended as an introduction into using phantom types in ReasonML.
Taking a look at the above definition from the Haskell wiki, it states that phantom types are parametrised types where not all parameters appear on the right-hand side. Let's try to see if we can implement a similar example as in said wiki.
// what if this was something browsers just gave us? | |
const { vdom } = document; | |
// this is same idea as React.createElement | |
// or any of the other similar appraoches | |
const newVirtualDom = vdom('div', {className: 'some-class'}, [ | |
vdom('p', null, 'hi') | |
]) | |
// if preferred, someone could easily use JSX and precompile it |
If you have already seen Richard Feldman's talk entitled "Making Impossible States Impossible" or have read "Designing with types: Making illegal states unrepresentable" then you can skip the explanations and just head straight to the Reason examples.
This post is intended to display how to model your Reason Application to prevent creating impossible states. The benefits of being able to design a feature in this way are avoiding having to deal with complex test scenarios when dealing with a set of business rules and a clear documentation of what is possible just by looking at the type definition. Long story short, let's see how this all works by implementing an example.
Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.
This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.
console.log(1); | |
(_ => console.log(2))(); | |
eval('console.log(3);'); | |
console.log.call(null, 4); | |
console.log.apply(null, [5]); | |
new Function('console.log(6)')(); | |
Reflect.apply(console.log, null, [7]) | |
Reflect.construct(function(){console.log(8)}, []); | |
Function.prototype.apply.call(console.log, null, [9]); | |
Function.prototype.call.call(console.log, null, 10); |