-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from drborges/bug-fixes
Bug fixes
- Loading branch information
Showing
43 changed files
with
1,305 additions
and
122 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import React from "react" | ||
|
||
import { App } from "../../short-circuit/App" | ||
|
||
describe("ShortCircuit App", () => { | ||
it("successfully renders components even when short circuit boolean logic is used", () => { | ||
cy.mount(<App />) | ||
|
||
cy.contains("store.state.flag1: false") | ||
cy.contains("store.state.flag2: false") | ||
cy.contains("store.state.flag3: false") | ||
cy.contains( | ||
"store.state.flag1 || store.state.flag2 || store.state.flag3 = false" | ||
) | ||
cy.contains( | ||
"store.state.flag1 && store.state.flag2 && store.state.flag3 = false" | ||
) | ||
|
||
cy.get("[data-testid='toggle-flag3']").click() | ||
|
||
cy.contains("store.state.flag1: false") | ||
cy.contains("store.state.flag2: false") | ||
cy.contains("store.state.flag3: true") | ||
cy.contains( | ||
"store.state.flag1 || store.state.flag2 || store.state.flag3 = true" | ||
) | ||
cy.contains( | ||
"store.state.flag1 && store.state.flag2 && store.state.flag3 = false" | ||
) | ||
|
||
cy.get("[data-testid='toggle-flag2']").click() | ||
|
||
cy.contains("store.state.flag1: false") | ||
cy.contains("store.state.flag2: true") | ||
cy.contains("store.state.flag3: true") | ||
cy.contains( | ||
"store.state.flag1 || store.state.flag2 || store.state.flag3 = true" | ||
) | ||
cy.contains( | ||
"store.state.flag1 && store.state.flag2 && store.state.flag3 = false" | ||
) | ||
|
||
cy.get("[data-testid='toggle-flag1']").click() | ||
|
||
cy.contains("store.state.flag1: true") | ||
cy.contains("store.state.flag2: true") | ||
cy.contains("store.state.flag3: true") | ||
cy.contains( | ||
"store.state.flag1 || store.state.flag2 || store.state.flag3 = true" | ||
) | ||
cy.contains( | ||
"store.state.flag1 && store.state.flag2 && store.state.flag3 = true" | ||
) | ||
|
||
cy.get("[data-testid='toggle-flag3']").click() | ||
|
||
cy.contains("store.state.flag1: true") | ||
cy.contains("store.state.flag2: true") | ||
cy.contains("store.state.flag3: false") | ||
cy.contains( | ||
"store.state.flag1 || store.state.flag2 || store.state.flag3 = true" | ||
) | ||
cy.contains( | ||
"store.state.flag1 && store.state.flag2 && store.state.flag3 = false" | ||
) | ||
|
||
cy.get("[data-testid='toggle-flag2']").click() | ||
|
||
cy.contains("store.state.flag1: true") | ||
cy.contains("store.state.flag2: false") | ||
cy.contains("store.state.flag3: false") | ||
cy.contains( | ||
"store.state.flag1 || store.state.flag2 || store.state.flag3 = true" | ||
) | ||
cy.contains( | ||
"store.state.flag1 && store.state.flag2 && store.state.flag3 = false" | ||
) | ||
|
||
cy.get("[data-testid='toggle-flag1']").click() | ||
|
||
cy.contains("store.state.flag1: false") | ||
cy.contains("store.state.flag2: false") | ||
cy.contains("store.state.flag3: false") | ||
cy.contains( | ||
"store.state.flag1 || store.state.flag2 || store.state.flag3 = false" | ||
) | ||
cy.contains( | ||
"store.state.flag1 && store.state.flag2 && store.state.flag3 = false" | ||
) | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from "react" | ||
|
||
import { TodoList, store } from "../../react-todo/store/useTodos" | ||
import SimpleTodoListApp from "../../react-todo/SimpleApp" | ||
|
||
describe("SimpleTodoList", () => { | ||
beforeEach(() => { | ||
store.setState(new TodoList()) | ||
}) | ||
|
||
it("preserves list items references within store upon removal", () => { | ||
cy.mount(<SimpleTodoListApp />) | ||
|
||
cy.findByTestId("add-todo-input").type("Clean the house") | ||
cy.findByText("Add").click() | ||
|
||
cy.findByTestId("add-todo-input").type("Walk the dogs") | ||
cy.findByText("Add") | ||
.click() | ||
.then(() => { | ||
const todo1 = store.state[0] | ||
const todo2 = store.state[1] | ||
|
||
cy.findByTestId(`todo-${todo1.id}`).within(() => { | ||
cy.findByText("Delete").click() | ||
}) | ||
|
||
cy.findByTestId(`todo-${todo2.id}`).within(() => { | ||
cy.findByText("Delete").click() | ||
}) | ||
}) | ||
}) | ||
}) |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from "react" | ||
|
||
import Summary from "./components/Summary" | ||
import NewTodoForm from "./components/NewTodoForm" | ||
import SimpleTodoList from "./components/SimpleTodoList" | ||
|
||
import "./index.css" | ||
|
||
export default function SimpleApp() { | ||
return ( | ||
<div className="app"> | ||
<h1>todos</h1> | ||
|
||
<div className="body"> | ||
<NewTodoForm /> | ||
<SimpleTodoList /> | ||
|
||
<div className="footer"> | ||
<Summary /> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, { memo } from "react" | ||
import { useArbor } from "@arborjs/react" | ||
|
||
import { TodoList, store } from "../store/useTodos" | ||
import TodoView from "./TodoView" | ||
|
||
export default memo(function SimpleTodoList() { | ||
const todos = useArbor(store) as TodoList | ||
|
||
return ( | ||
<div className="todo-list"> | ||
{todos.map((todo) => ( | ||
<TodoView key={todo.uuid} id={todo.uuid} /> | ||
))} | ||
</div> | ||
) | ||
}) |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from "react" | ||
|
||
import { Highlight } from "./components/Highlight" | ||
import { StoreState } from "./components/StoreState" | ||
import { Actions } from "./components/Actions" | ||
import { AreThereAnyFlagsTrue } from "./components/AreThereAnyFlagsTrue" | ||
import { AreAllFlagsTrue } from "./components/AreAllFlagsTrue" | ||
|
||
import "./styles.css" | ||
|
||
export function App() { | ||
return ( | ||
<Highlight label="<App />" key={Math.random()}> | ||
<Actions /> | ||
<StoreState /> | ||
<AreThereAnyFlagsTrue /> | ||
<AreAllFlagsTrue /> | ||
</Highlight> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from "react" | ||
|
||
import { Highlight } from "./Highlight" | ||
import { store } from "../store" | ||
|
||
export function Actions() { | ||
return ( | ||
<Highlight label="<Actions />" key={Math.random()}> | ||
<button data-testid="toggle-flag1" onClick={store.state.toggleFlag1}> | ||
Toggle <code>store.state.flag1</code> | ||
</button> | ||
<button data-testid="toggle-flag2" onClick={store.state.toggleFlag2}> | ||
Toggle <code>store.state.flag2</code> | ||
</button> | ||
<button data-testid="toggle-flag3" onClick={store.state.toggleFlag3}> | ||
Toggle <code>store.state.flag3</code> | ||
</button> | ||
</Highlight> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from "react" | ||
import { useArbor } from "@arborjs/react" | ||
|
||
import { Highlight } from "./Highlight" | ||
import { store } from "../store" | ||
|
||
export function AreAllFlagsTrue() { | ||
const app = useArbor(store) | ||
return ( | ||
<Highlight label="<AreAllFlagsTrue />" key={Math.random()}> | ||
<code> | ||
store.state.flag1 && store.state.flag2 && store.state.flag3 ={" "} | ||
{(app.flag1 && app.flag2 && app.flag3).toString()} | ||
</code> | ||
</Highlight> | ||
) | ||
} |
17 changes: 17 additions & 0 deletions
17
examples/short-circuit/components/AreThereAnyFlagsTrue.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from "react" | ||
import { useArbor } from "@arborjs/react" | ||
|
||
import { Highlight } from "./Highlight" | ||
import { store } from "../store" | ||
|
||
export function AreThereAnyFlagsTrue() { | ||
const app = useArbor(store) | ||
return ( | ||
<Highlight label="<AreThereAnyFlagsTrue />" key={Math.random()}> | ||
<code> | ||
store.state.flag1 || store.state.flag2 || store.state.flag3 ={" "} | ||
{(app.flag1 || app.flag2 || app.flag3).toString()} | ||
</code> | ||
</Highlight> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from "react" | ||
|
||
import { useAnimatedClassName } from "../hooks/useAnimatedClassName" | ||
|
||
export function Highlight({ | ||
key, | ||
children, | ||
label, | ||
}: { | ||
key: number | ||
children: React.ReactNode | ||
label: string | ||
}) { | ||
const className = useAnimatedClassName(key) | ||
return ( | ||
<div className={`highlight ${className}`}> | ||
<span>{label}</span> | ||
{children} | ||
</div> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from "react" | ||
import { useArbor } from "@arborjs/react" | ||
|
||
import { Highlight } from "./Highlight" | ||
import { store } from "../store" | ||
|
||
export function StoreState() { | ||
const state = useArbor(store) | ||
|
||
return ( | ||
<Highlight label="<StoreState />" key={Math.random()}> | ||
<div> | ||
<code>store.state.flag1: {state.flag1.toString()}</code> | ||
</div> | ||
<div> | ||
<code>store.state.flag2: {state.flag2.toString()}</code> | ||
</div> | ||
<div> | ||
<code>store.state.flag3: {state.flag3.toString()}</code> | ||
</div> | ||
</Highlight> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useEffect, useState } from "react" | ||
|
||
export function useAnimatedClassName(key: number) { | ||
const [className, setClassName] = useState("") | ||
|
||
useEffect(() => { | ||
setClassName("animate") | ||
const timeoutId = setTimeout(() => { | ||
setClassName("") | ||
}, 1000) | ||
|
||
return () => clearTimeout(timeoutId) | ||
}, [key]) | ||
|
||
return className | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Arbor } from "@arborjs/store" | ||
|
||
import { ShortCircuitApp } from "./models/ShortCircuitApp" | ||
|
||
export const store = new Arbor(new ShortCircuitApp()) |
Oops, something went wrong.