Skip to content

Instantly share code, notes, and snippets.

View bernard-ng's full-sized avatar
🏘️
working from home

Bernard Ngandu bernard-ng

🏘️
working from home
View GitHub Profile
set -g status-justify left # Aligne les titres de fenetres a gauche
set -g status-bg colour1 # Status bar noir sur rouge
set -g status-fg colour0 #
set -g status-interval 2 # Evite des bug de refraichissement
setw -g window-status-current-fg colour1 # Inversion des couleur pour l'onglet selectione
setw -g window-status-current-bg colour0 #
set-option -g history-limit 10000 # Permet de scroller 10k lignes
set -g history-limit 10000 #
<?php
$initialState = [
'count' => [
'count' => 1
],
'sum' => 0
];
function sumReducer($state, $action) {
switch($action['type']) {
<?php
function combineReducers(array $reducers) {
return function(array $state, $action) use ($reducers) {
$newState = $state;
foreach($reducers as $stateKey => $reducer) {
if(!isset($newState[$stateKey])) {
$newState[$stateKey] = [];
}
$newState[$stateKey] = $reducer($newState[$stateKey], $action);
}
rootReducer = combineReducers({potato: potatoReducer, tomato: tomatoReducer});
<?php
const INCREMENT_BY_ACTION = 'INCREMENT_BY';
function countReducer(array $state, $action) {
switch($action['type']) {
case INCREMENT_BY_ACTION;
$value = $action['value'] ?? 0;
return array_replace([], $state, ['count' => $state['count'] + $value]);
case INCREMENT_ACTION:
return array_replace([], $state, ['count' => $state['count'] + 1]);
<?php
class Store
{
protected array $state;
protected Closure $reducer;
protected array $listeners = [];
public function __construct( callable $reducer, array $initialState)
{
<?php
$store->subscribe(function($state) {
print_r($state);
});
# Que diriez-vous d'un envoi :
# ...
public function dispatch(array $action)
{
<?php
#....
protected array $listeners = [];
public function getState()
{
return $this->state;
}
public function subscribe(callable $listener)
<?php
class Store
{
protected array $state;
protected Closure $reducer;
public function __construct(callable $reducer, array $initialState)
{
$this->state = $initialState;
$this->reducer = Closure::fromCallable($reducer);
}
<?php
function countReducer(array $state, $action) {
switch($action['type']) {
case INCREMENT_ACTION:
return array_replace([], $state, ['count' => $state['count'] + 1]);
case DECREMENT_ACTION:
return array_replace([], $state, ['count' => $state['count'] - 1]);
default:
return $state;
}