This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const add1ToPopuation = (store) => (state) => { | |
state.cities[0].population[0].population++; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const changeWeatherDescription = (store, description) => { | |
store.setState((state) => { | |
state.cities[0].weatherStatus.current.weather[0].description = description; | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import Immer from "immer"; | |
import globalHook from "use-global-hook"; | |
import * as actions from "../actions"; | |
import { initialState } from "./initialState"; | |
const options = { Immer }; | |
const useGlobal = globalHook(React, initialState, actions, options); | |
export default useGlobal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import globalHook from 'use-global-hook'; | |
const initialState = { | |
counter: 0, | |
}; | |
const actions = { | |
addToCounter: (store, amount) => { | |
const newCounterValue = store.state.counter + amount; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
store.setState((state) => { | |
state.cities[0].weatherStatus.current.weather[0].description = "Clear sky"; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const newWeatherItem = { ...state.cities[0].weatherStatus.current.weather[0], description: "Clear sky" } | |
const newWeather = [...state.cities[0].weatherStatus.current.weather] | |
newWeather[0] = newWeatherItem | |
const newCurrent = { ...state.cities[0].weatherStatus.current, weather: newWeather } | |
const newWeatherStatus = { ...state.cities[0].weatherStatus, current: newCurrent } | |
const newCities = [...state.cities] | |
newCities[0] = { ...newCities[0], weatherStatus: newWeatherStatus } | |
const newState = { ...state, cities: newCities } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const state = { | |
cities: [ | |
{ | |
name: "Chicago", | |
state: "Illinois", | |
population: [ | |
{ | |
year: 2020, | |
population: 2713984 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://unpkg.com/vue/dist/vue.min.js"></script> | |
<div id="main"> | |
<h1>Shopping cart</h1> | |
<p>Apples: {{ products.apple }}</p> | |
<p>Bananas: {{ products.banana }}</p> | |
<p>Oranges: {{ products.orange }}</p> | |
</div> | |
<script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Products catalog</h1> | |
<h2>Apple <button value="apple">Add to cart</button></h2> | |
<h2>Banana <button value="banana">Add to cart</button></h2> | |
<h2>Orange <button value="orange">Add to cart</button></h2> | |
<script> | |
const addToCart = e => window.parent.postMessage(e.target.value, "*"); | |
document | |
.querySelectorAll("button") | |
.forEach(button => button.addEventListener("click", addToCart)); |
NewerOlder