Skip to content

Instantly share code, notes, and snippets.

View oshell's full-sized avatar
🎯
Focusing

oshell oshell

🎯
Focusing
View GitHub Profile
'.source.js':
'onclick':
'prefix': 'click'
'body': '$("$1").on("click", function(){ \n\t$2 \n});'
$('$1$').on('click', function(){
$2$
});
@oshell
oshell / App.js
Last active December 9, 2018 12:34
class App extends Component {
constructor(props){
super(props);
this.state = {
restaurants: initialRestaurants,
sorting: initialSorting,
}
this.toggleFavourite = this.toggleFavourite.bind(this);
@oshell
oshell / App.js
Created December 8, 2018 14:38
Redux App.js
const App = () => {
return(
<Provider store={store}>
<Container>
<SearchBar />
<RestaurantList />
</Container>
</Provider>
);
}
import React, { Component } from 'react';
import { Input as SemanticInput } from 'semantic-ui-react';
import { connect } from 'react-redux';
import { search } from '../../actions/index';
class Input extends Component {
render() {
return(
<SemanticInput
onChange={(e) => {this.props.search(e.target.value);}}
@oshell
oshell / actions.js
Created December 8, 2018 15:14
Action Creator
export const SEARCH = 'SEARCH';
export const search = (term) => ({
type: SEARCH,
payload: {term}
});
@oshell
oshell / restaurantsReducer.js
Created December 8, 2018 15:23
restaurantsReducer.js
import * as actions from '../actions/index';
import Utility from '../controller/Utility/Utility';
export const restaurantsReducer = (state = {}, action) => {
switch (action.type) {
case actions.SEARCH:
return Utility.search(action.payload.term, state);
default:
return state;
}
@oshell
oshell / rootReducer.js
Created December 8, 2018 15:43
rootReducer.js
import { combineReducers } from 'redux';
import { restaurantsReducer } from './restaurantsReducer';
export const rootReducer = combineReducers({
restaurantsReducer
});
@oshell
oshell / store.js
Created December 8, 2018 15:46
store.js
import { createStore } from 'redux';
import { rootReducer } from './reducers/rootReducer';
export const store = createStore(rootReducer);
@oshell
oshell / App.js
Created December 8, 2018 15:48
App.js
import React from 'react';
import { Container } from 'semantic-ui-react'
import RestaurantList from '../../container/RestaurantList/RestaurantList';
import SearchBar from '../SearchBar/SearchBar';
import { Provider } from 'react-redux';
import { store } from '../../store';
const App = () => {
return(
<Provider store={store}>