This file contains hidden or 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 function myFunction (num) { | |
| if (num % 15 === 0) return 'pineapple'; | |
| if (num % 3 === 0) return 'pine'; | |
| if (num % 5 === 0) return 'apple'; | |
| return num; | |
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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> |
NewerOlder