Skip to content

Instantly share code, notes, and snippets.

View adamkleingit's full-sized avatar

Adam Klein adamkleingit

View GitHub Profile
@adamkleingit
adamkleingit / mockup.md
Last active January 27, 2022 11:30
Timer App

Timer App

Please create an app for managing timed tasks.

  1. The user can input a text and click Add
  2. A new task is added with the title, and 00:00 time, and a play button.
  3. Clicking Play will play this task: the timer will start running, and the icon will change to a pause icon. Also - any other running task will be paused.
  4. Clicking Pause will pause the task.
  5. The total time is always updated.
const renderGridRowCell = (colConfig, row, index) => {
const CustomValue = colConfig.component;
const value = CustomValue ? <CustomValue data={ row }/> : row[colConfig.field];
return <td key={ index }>{ value }</td>;
};
@adamkleingit
adamkleingit / package-lock.json
Last active February 20, 2018 08:12
Files for deploying Node.JS to Heroku
(automatically generated from npm)
"Redux forces you to write good code" - I've heard that sentence many times.
In fact - it's quite easy to write bad code with Redux, as I've seen many times.
In this talk I will show some bad practices and techniques with Redux, and how to avoid them.
@adamkleingit
adamkleingit / redux-hooks.js
Last active November 8, 2018 06:32
Experimenting with Hooks and Redux
const useStore = () => {
const { store } = useContext(ReactReduxContext);
return store;
};
const useSelector = selector => {
const store = useStore();
const prevState = selector(store.getState());
import {createStore} from 'reusable';
export const useCurrentUser = createStore(() => {
const [user, setUser] = useState({...});
...
return {
user,
...
}
});
@adamkleingit
adamkleingit / simple.stores.js
Created July 9, 2019 10:19
Simple Reusable Stores Example
import {createStore} from 'reusable';
export const useLocale = createStore(() => useState('en'));
export const useSomething = createStore(() => useReducer(...));
import {useCurrentUser} from '../stores/currentUser.store';
const Comp1 = () => {
const { user } = useCurrentUser();
...
}
const Comp2 = () => {
const { user } = useCurrentUser(); // Same user
...
@adamkleingit
adamkleingit / App.jsx
Created July 9, 2019 10:29
App with ReusableProvider
import {ReusableProvider} from 'reusable';
export const App = () => (
<ReusableProvider>
{ /* App Components */ }
</ReusableProvider>
);
@adamkleingit
adamkleingit / ReusableSelectors.js
Created July 9, 2019 10:31
Reusable Selectors
import {createStore} from 'reusable';
const useTodos = createStore(() => useState([]));
const Comp = () => {
const todosCount = useTodos(
([todos]) => todos.length
);
...
};