-
Notifications
You must be signed in to change notification settings - Fork 146
Add MapEntries control flow component.
#728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
85a6fbf
add entries to dev
AlexErrant 1500975
add <MapEntries/>
AlexErrant ab7b9dd
demo that ReactiveMap works as expected
AlexErrant cf11535
add changeset
AlexErrant 37c3d35
too much pasta
AlexErrant 9529fd7
mv and small tweaks
AlexErrant 5f04a47
add to main readme
AlexErrant d27c498
mv back
AlexErrant 7712d19
test
AlexErrant 1d13567
store => signal
AlexErrant 3f1cf04
Apply suggestions from code review
AlexErrant 973ee01
Add MapEntries to package.json
thetarnav 533c821
simplify
AlexErrant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@solid-primitives/keyed": minor | ||
| --- | ||
|
|
||
| Add `MapEntries` control flow component. |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| // changes to this file might be applicable to similar files - grep 95DB7339-BB2A-4F06-A34A-25DDF8BF7AF7 | ||
thetarnav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import { createStore, produce } from "solid-js/store"; | ||
| import { createEffect } from "solid-js"; | ||
| import { Entries } from "../src/index.js"; | ||
| import { TransitionGroup } from "solid-transition-group"; | ||
|
|
||
| const foods = [ | ||
| "oatmeal", | ||
| "plantains", | ||
| "cranberries", | ||
| "chickpeas", | ||
| "tofu", | ||
| "Parmesan cheese", | ||
| "amaretto", | ||
| "sunflower seeds", | ||
| "grapes", | ||
| "vegemite", | ||
| "pasta", | ||
| "cider", | ||
| "chicken", | ||
| "pinto beans", | ||
| "bok choy", | ||
| "sweet peppers", | ||
| "Cappuccino Latte", | ||
| "corn", | ||
| "broccoli", | ||
| "brussels sprouts", | ||
| "bread", | ||
| "milk", | ||
| "honey", | ||
| "chips", | ||
| "cookie", | ||
| ]; | ||
| const randomIndex = (list: readonly any[]): number => Math.floor(Math.random() * list.length); | ||
| const getRandomFood = () => foods[randomIndex(foods)]!; | ||
| const randomKey = (record: Record<string, string>): string => { | ||
| const keys = Object.keys(record); | ||
| return keys[randomIndex(keys)]!; | ||
| }; | ||
|
|
||
| export default function App() { | ||
| const [store, setStore] = createStore<Record<string, string>>({ | ||
| [Math.random()]: "bread", | ||
| [Math.random()]: "milk", | ||
| [Math.random()]: "honey", | ||
| [Math.random()]: "chips", | ||
| [Math.random()]: "cookie", | ||
| }); | ||
|
|
||
| const addRandom = () => { | ||
| setStore(Math.random().toString(), getRandomFood()); | ||
| }; | ||
| const removeRandom = () => setStore(p => ({ [randomKey(p)]: undefined })); | ||
| const clone = () => setStore("entries", p => JSON.parse(JSON.stringify(p))); | ||
| const changeRandomValue = () => setStore(p => ({ [randomKey(p)]: getRandomFood() })); | ||
|
|
||
| return ( | ||
| <> | ||
| <div class="wrapper-h"> | ||
| <button class="btn" onclick={addRandom}> | ||
| Add | ||
| </button> | ||
| <button class="btn" onclick={removeRandom}> | ||
| Remove | ||
| </button> | ||
| <button class="btn" onclick={changeRandomValue}> | ||
| Change value | ||
| </button> | ||
| <button class="btn" onclick={clone}> | ||
| Clone | ||
| </button> | ||
| </div> | ||
| <div class="wrapper-h flex-wrap"> | ||
| <TransitionGroup name="fade"> | ||
| <Entries of={store} fallback={<p class="bg-yellow-500 p-1 transition-all">No items.</p>}> | ||
| {(key, value, index) => { | ||
| createEffect(() => { | ||
| console.log("Effect:", key, value()); | ||
| }); | ||
| return ( | ||
| <div class="node relative transition-all duration-500"> | ||
| {index()}. {value()} | ||
| <div class="bg-dark-500 text-light-900 absolute -bottom-2 left-2 px-1 text-[9px]"> | ||
| ID: {key} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }} | ||
| </Entries> | ||
| </TransitionGroup> | ||
| </div> | ||
| </> | ||
| ); | ||
| } | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // changes to this file might be applicable to similar files - grep 95DB7339-BB2A-4F06-A34A-25DDF8BF7AF7 | ||
thetarnav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import { createEffect, createSignal } from "solid-js"; | ||
| import { MapEntries } from "../src/index.js"; | ||
| import { TransitionGroup } from "solid-transition-group"; | ||
|
|
||
| const foods = [ | ||
| "oatmeal", | ||
| "plantains", | ||
| "cranberries", | ||
| "chickpeas", | ||
| "tofu", | ||
| "Parmesan cheese", | ||
| "amaretto", | ||
| "sunflower seeds", | ||
| "grapes", | ||
| "vegemite", | ||
| "pasta", | ||
| "cider", | ||
| "chicken", | ||
| "pinto beans", | ||
| "bok choy", | ||
| "sweet peppers", | ||
| "Cappuccino Latte", | ||
| "corn", | ||
| "broccoli", | ||
| "brussels sprouts", | ||
| "bread", | ||
| "milk", | ||
| "honey", | ||
| "chips", | ||
| "cookie", | ||
| ]; | ||
| const randomIndex = (list: readonly any[]): number => Math.floor(Math.random() * list.length); | ||
| const getRandomFood = () => foods[randomIndex(foods)]!; | ||
| const randomKey = (map: Map<string, string>): string => { | ||
| const keys = Array.from(map.keys()); | ||
| return keys[randomIndex(keys)]!; | ||
| }; | ||
|
|
||
| export default function App() { | ||
| const [map, setMap] = createSignal( | ||
| new Map([ | ||
| [Math.random().toString(), "bread"], | ||
| [Math.random().toString(), "milk"], | ||
| [Math.random().toString(), "honey"], | ||
| [Math.random().toString(), "chips"], | ||
| [Math.random().toString(), "cookie"], | ||
| ]), | ||
| ); | ||
|
|
||
| const addRandom = () => { | ||
| setMap(p => { | ||
| p.set(Math.random().toString(), getRandomFood()); | ||
| return new Map(p); | ||
| }); | ||
| }; | ||
| const removeRandom = () => | ||
| setMap(p => { | ||
| p.delete(randomKey(p)); | ||
| return new Map(p); | ||
| }); | ||
| const clone = () => setMap(p => new Map(p)); | ||
| const changeRandomValue = () => | ||
| setMap(p => { | ||
| p.set(randomKey(p), getRandomFood()); | ||
| return new Map(p); | ||
| }); | ||
|
|
||
| return ( | ||
| <> | ||
| <div class="wrapper-h"> | ||
| <button class="btn" onclick={addRandom}> | ||
| Add | ||
| </button> | ||
| <button class="btn" onclick={removeRandom}> | ||
| Remove | ||
| </button> | ||
| <button class="btn" onclick={changeRandomValue}> | ||
| Change value | ||
| </button> | ||
| <button class="btn" onclick={clone}> | ||
| Clone | ||
| </button> | ||
| </div> | ||
| <div class="wrapper-h flex-wrap"> | ||
| <TransitionGroup name="fade"> | ||
| <MapEntries | ||
| of={map()} | ||
| fallback={<p class="bg-yellow-500 p-1 transition-all">No items.</p>} | ||
| > | ||
| {(key, value, index) => { | ||
| createEffect(() => { | ||
| console.log("Effect:", key, value()); | ||
| }); | ||
| return ( | ||
| <div class="node relative transition-all duration-500"> | ||
| {index()}. {value()} | ||
| <div class="bg-dark-500 text-light-900 absolute -bottom-2 left-2 px-1 text-[9px]"> | ||
| ID: {key} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }} | ||
| </MapEntries> | ||
| </TransitionGroup> | ||
| </div> | ||
| </> | ||
| ); | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,8 @@ | |
| "list": [ | ||
| "keyArray", | ||
| "Key", | ||
| "Entries" | ||
| "Entries", | ||
| "MapEntries" | ||
| ], | ||
| "category": "Control Flow" | ||
| }, | ||
|
|
||
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.