Skip to content

Instantly share code, notes, and snippets.

View helloitsjoe's full-sized avatar

Joe Boyle helloitsjoe

View GitHub Profile
<script>
const initialState = { movies: ['Mad Max'] };
const store = createStore(reducer, initialState);
$: mMovies = $store.movies.filter((movie) => movie.includes('M'));
</script>
<div>{mMovies.join(', ')}, brought to you by the letter M</div>
<script>
const reducer = (state, action) => {
switch(action.type) {
case 'add_movie':
return { ...state, movies: [...state.movies, action.id] };
default:
return state;
}
};
import { writable } from 'svelte/store';
const createStore = (reducer, initialState) => {
const { subscribe, update } = writable(initialState);
const dispatch = (action) => update((state) => reducer(state, action));
return { subscribe, dispatch };
};
<script>
export let movies; // <-- This is how Svelte defines a prop
const addBatman = () => {
movies = [...movies, 'Batman'];
};
</script>
<div>{movies.join(', ')}</div>
<button on:click={addBatman}>Add Batman</button>
<script>
import { MoviePage, MovieBrowser } from './components';
let movies = ['Blade Runner', 'Footloose'];
</script>
<MoviePage bind:movies />
<MovieBrowser bind:movies />
<MovieDetail bind:movies />
@helloitsjoe
helloitsjoe / cancel-in-action-reducer.js
Last active February 12, 2021 14:10
Cancel with useReducer
// This will work
const reducer = (state, action) => {
if (action.type === CANCEL) {
return state;
}
switch (action.type) {
case FETCHING:
return {...state, text: 'Fetching...'};
case SUCCESS:
javascript:(function(){s=document.body.style;s.width='720px';s.margin='auto'})()
server {
listen 80;
server_name localhost;
# Reverse proxy
location /sentiment/ {
proxy_pass http://sa-web-app-lb:8080/;
}
location / {
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: sa-ingress
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: 'false'
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http: