Skip to content

Instantly share code, notes, and snippets.

@bernard-ng
Created July 20, 2020 11:06
Show Gist options
  • Save bernard-ng/5318a99923844b5111fe48acba925075 to your computer and use it in GitHub Desktop.
Save bernard-ng/5318a99923844b5111fe48acba925075 to your computer and use it in GitHub Desktop.
<?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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment