createSlice
createAction
createAsyncThunk
configureStore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// user module | |
const receive = (_user, sender, message) => { | |
console.log(`${new Date().toLocaleString()} [${sender}]: ${message}`); | |
}; | |
// chat room module | |
const createChatRoom = (users = []) => ({ | |
users | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ChatRoom { | |
constructor(users = []) { | |
this.users = users; | |
} | |
addUser(user) { | |
this.users.push(user); | |
} | |
sendMessage(user, message) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const execute = (command, ...args) => command(...args); | |
function PlaceOrderCommand(order, id) { | |
return orders => { | |
const result = [...orders, { id }]; | |
console.log(`You have successfully ordered ${order} (${id})`); | |
return { success: true, result }; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns number-puzzles.imbaru | |
(:refer-clojure :exclude [==]) ;; Prevent ns conflict | |
(:require [clojure.core.logic :refer :all])) | |
(def answers (run* [q] | |
(fresh [r1 r2 r3 r4 | |
r5 r6 r7 r8 | |
r9 r10 r11 r12 | |
r13 r14 r15 r16] |
- UI should be an afterthought
- Write code that allows to sepearate business logic frow UI.
- Write code that allows to inject any hard-to-test, too-verbose, want-this-mocked stuff logic.
- It has special place for handling business logic, called middleware.
- Popular middleware have a mechanism for context injection. If you are writing your own custom middleware, then you probably should think about adding this too.
UI should be an afterthought
- Better testability via the fewer levels of indirection. To trigger business processes you call methods or invoke functions, not clicking buttons.
- Better testability via DI in some form. In React code
jest.mock
is the only "unobtrusive" way to replace dependencies. - Discoverability. Business logic isn't scattered across a bunch of components.
- Reusability. Sometimes you want to reuse only business logic and not the UI tied to it.
- Readability. It is easier to reason about business logic.
-
Visual documentation
- Discoverability (Easier to find existing components. Potentially works for designers too. As a result, we are saving time because we are not doing the same thing again and again)
- Regression (Breaking design or API changes will be reflected)
- Describes component API (And edge cases)
- Hints to intended usage
-
Faster design delivery (than having component embedded into the page)
- Early design feedback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns logical-boys-girls.core | |
(:require [clojure.core.logic :as logic] | |
[clojure.core.logic.fd :as fd])) | |
(logic/run* | |
[q] | |
(let [students-count (fd/interval 1 100)] | |
(logic/fresh [boys girls h-girls q-girls h-boys q-boys] | |
;; boring part | |
;; every lvar belongs to number from interval |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* The Reasoned Schemer | |
* Seven More Languages in Seven Weeks, Brues Tate, Chapter 6. miniKanren | |
* Joy Of Cloure, Michael Fogus, Chapter 16. Thinking Programs | |
* https://www.youtube.com/watch?v=lzCIyvFgUVk |
NewerOlder