Elixir-flavored Redux:
defmodule Store do
def start_link(reducer, preloadedState) do
Agent.start_link(fn -> { reducer, preloadedState } end)
end
def start_link(reducer) do
Agent.start_link(fn -> { reducer, nil } end)
db.articles.aggregate( | |
[{ $match: { | |
$or: [{ | |
score: { $gt: 90 } | |
}, { | |
author: "dave" | |
}}] | |
}}] | |
); |
// Given these documents in a collection | |
{ "_id" : ObjectId("512bc95fe835e68f199c8686"), "author" : "dave", "score" : 80 } | |
{ "_id" : ObjectId("512bc962e835e68f199c8687"), "author" : "dave", "score" : 85 } | |
{ "_id" : ObjectId("55f5a192d4bede9ac365b257"), "author" : "ahn", "score" : 60 } | |
{ "_id" : ObjectId("55f5a192d4bede9ac365b258"), "author" : "li", "score" : 55 } | |
{ "_id" : ObjectId("55f5a1d3d4bede9ac365b259"), "author" : "annT", "score" : 60 } | |
{ "_id" : ObjectId("55f5a1d3d4bede9ac365b25a"), "author" : "li", "score" : 94 } | |
{ "_id" : ObjectId("55f5a1d3d4bede9ac365b25b"), "author" : "ty", "score" : 95 } | |
// Apply this aggregation |
Elixir-flavored Redux:
defmodule Store do
def start_link(reducer, preloadedState) do
Agent.start_link(fn -> { reducer, preloadedState } end)
end
def start_link(reducer) do
Agent.start_link(fn -> { reducer, nil } end)
import { createStore } from 'redux' | |
function counter(state = 0, action) { | |
switch (action.type) { | |
case 'INCREMENT': | |
return state + 1 | |
case 'DECREMENT': | |
return state - 1 | |
default: | |
return state |
let currentListeners = [] | |
let nextListeners = currentListeners | |
... | |
function subscribe(listener) { | |
if (typeof listener !== 'function') { | |
throw new Error('Expected listener to be a function.') | |
} |
declare type Dispatch<A: { type: $Subtype<string> }> = (action: A) => A; |
function dispatch(action) { | |
if (!isPlainObject(action)) { | |
throw new Error( | |
'Actions must be plain objects. ' + | |
'Use custom middleware for async actions.' | |
) | |
} | |
if (typeof action.type === 'undefined') { | |
throw new Error( |
... | |
let currentState = preloadedState | |
... | |
function getState() { | |
return currentState | |
} |
export default function createStore(reducer, preloadedState) { | |
let state = preloadedState | |
let listeners = [] | |
let dispatching = false | |
function getState() { | |
return state | |
} | |
function dispatch(action) { |
import { createStore } from 'redux'; | |
const app = createStore((state, action) => { return state }, { booted_at: new Date() }); |