Skip to content

Commit 61c8e14

Browse files
authored
Update Examples page with embeds (reduxjs#3320)
* Add a package.json to counter-vanilla for CodeSandbox use * Fix example links and add first sandbox embed * Try adding Parcel setup for counter-vanilla * Add counter-vanilla sandbox with temp branch link * Add sandboxes for other examples * Add counter-vanilla README * Format readme * Remove todos-flow embed due to compile issues
1 parent 32ac7e6 commit 61c8e14

File tree

3 files changed

+83
-35
lines changed

3 files changed

+83
-35
lines changed

docs/introduction/Examples.md

+54-35
Original file line numberDiff line numberDiff line change
@@ -7,81 +7,89 @@ hide_title: true
77

88
# Examples
99

10-
Redux is distributed with a few examples in its [source code](https://github.com/reactjs/redux/tree/master/examples). Most of these examples are also on [CodeSandbox](https://codesandbox.io), an online editor that lets you play with the examples online.
10+
Redux is distributed with a few examples in its [source code](https://github.com/reduxjs/redux/tree/master/examples). Most of these examples are also on [CodeSandbox](https://codesandbox.io), an online editor that lets you play with the examples online.
1111

1212
## Counter Vanilla
1313

14-
Run the [Counter Vanilla](https://github.com/reactjs/redux/tree/master/examples/counter-vanilla) example:
14+
Run the [Counter Vanilla](https://github.com/reduxjs/redux/tree/master/examples/counter-vanilla) example:
1515

1616
```sh
17-
git clone https://github.com/reactjs/redux.git
17+
git clone https://github.com/reduxjs/redux.git
1818

1919
cd redux/examples/counter-vanilla
2020
open index.html
2121
```
2222

23+
Or check out the [sandbox](https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/counter-vanilla):
24+
25+
<iframe src="https://codesandbox.io/embed/github/reduxjs/redux/tree/master/examples/counter-vanilla" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>
26+
2327
It does not require a build system or a view framework and exists to show the raw Redux API used with ES5.
2428

2529
## Counter
2630

27-
Run the [Counter](https://github.com/reactjs/redux/tree/master/examples/counter) example:
31+
Run the [Counter](https://github.com/reduxjs/redux/tree/master/examples/counter) example:
2832

2933
```sh
30-
git clone https://github.com/reactjs/redux.git
34+
git clone https://github.com/reduxjs/redux.git
3135

3236
cd redux/examples/counter
3337
npm install
3438
npm start
3539
```
3640

37-
Or check out the [sandbox](https://codesandbox.io/s/github/reactjs/redux/tree/master/examples/counter):
41+
Or check out the [sandbox](https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/counter):
3842

39-
{% embed data="{\"url\":\"https://codesandbox.io/embed/github/reactjs/redux/tree/master/examples/counter\",\"type\":\"link\",\"title\":\"CodeSandbox\",\"description\":\"CodeSandbox is an online editor tailored for web applications.\",\"icon\":{\"type\":\"icon\",\"url\":\"https://codesandbox.io/favicon.ico\",\"aspectRatio\":0},\"thumbnail\":{\"type\":\"thumbnail\",\"url\":\"https://codesandbox.io/static/img/banner.png\",\"width\":1200,\"height\":630,\"aspectRatio\":0.525}}" %}
43+
<iframe src="https://codesandbox.io/embed/github/reduxjs/redux/tree/master/examples/counter" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>
4044

41-
This is the most basic example of using Redux together with React. For simplicity, it re-renders the React component manually when the store changes. In real projects, you will likely want to use the highly performant [React Redux](https://github.com/reactjs/react-redux) bindings instead.
45+
This is the most basic example of using Redux together with React. For simplicity, it re-renders the React component manually when the store changes. In real projects, you will likely want to use the highly performant [React Redux](https://github.com/reduxjs/react-redux) bindings instead.
4246

4347
This example includes tests.
4448

4549
## Todos
4650

47-
Run the [Todos](https://github.com/reactjs/redux/tree/master/examples/todos) example:
51+
Run the [Todos](https://github.com/reduxjs/redux/tree/master/examples/todos) example:
4852

4953
```sh
50-
git clone https://github.com/reactjs/redux.git
54+
git clone https://github.com/reduxjs/redux.git
5155

5256
cd redux/examples/todos
5357
npm install
5458
npm start
5559
```
5660

57-
Or check out the [sandbox](https://codesandbox.io/s/github/reactjs/redux/tree/master/examples/todos).
61+
Or check out the [sandbox](https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/todos):
62+
63+
<iframe src="https://codesandbox.io/embed/github/reduxjs/redux/tree/master/examples/todos" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>
5864

59-
This is the best example to get a deeper understanding of how the state updates work together with components in Redux. It shows how reducers can delegate handling actions to other reducers, and how you can use [React Redux](https://github.com/reactjs/react-redux) to generate container components from your presentational components.
65+
This is the best example to get a deeper understanding of how the state updates work together with components in Redux. It shows how reducers can delegate handling actions to other reducers, and how you can use [React Redux](https://github.com/reduxjs/react-redux) to generate container components from your presentational components.
6066

6167
This example includes tests.
6268

6369
## Todos with Undo
6470

65-
Run the [Todos with Undo](https://github.com/reactjs/redux/tree/master/examples/todos-with-undo) example:
71+
Run the [Todos with Undo](https://github.com/reduxjs/redux/tree/master/examples/todos-with-undo) example:
6672

6773
```sh
68-
git clone https://github.com/reactjs/redux.git
74+
git clone https://github.com/reduxjs/redux.git
6975

7076
cd redux/examples/todos-with-undo
7177
npm install
7278
npm start
7379
```
7480

75-
Or check out the [sandbox](https://codesandbox.io/s/github/reactjs/redux/tree/master/examples/todos-with-undo).
81+
Or check out the [sandbox](https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/todos-with-undo):
82+
83+
<iframe src="https://codesandbox.io/embed/github/reduxjs/redux/tree/master/examples/todos-with-undo" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>
7684

7785
This is a variation on the previous example. It is almost identical, but additionally shows how wrapping your reducer with [Redux Undo](https://github.com/omnidan/redux-undo) lets you add a Undo/Redo functionality to your app with a few lines of code.
7886

7987
## Todos w/ Flow
8088

81-
Run the [Todos w/ Flow](https://github.com/reactjs/redux/tree/master/examples/todos-flow) example:
89+
Run the [Todos w/ Flow](https://github.com/reduxjs/redux/tree/master/examples/todos-flow) example:
8290

8391
```sh
84-
git clone https://github.com/reactjs/redux.git
92+
git clone https://github.com/reduxjs/redux.git
8593

8694
cd redux/examples/todos-flow
8795
npm install
@@ -92,78 +100,86 @@ This is like the previous Todos examples, but shows how to use Redux in conjunct
92100

93101
## TodoMVC
94102

95-
Run the [TodoMVC](https://github.com/reactjs/redux/tree/master/examples/todomvc) example:
103+
Run the [TodoMVC](https://github.com/reduxjs/redux/tree/master/examples/todomvc) example:
96104

97105
```sh
98-
git clone https://github.com/reactjs/redux.git
106+
git clone https://github.com/reduxjs/redux.git
99107

100108
cd redux/examples/todomvc
101109
npm install
102110
npm start
103111
```
104112

105-
Or check out the [sandbox](https://codesandbox.io/s/github/reactjs/redux/tree/master/examples/todomvc).
113+
Or check out the [sandbox](https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/todomvc):
114+
115+
<iframe src="https://codesandbox.io/embed/github/reduxjs/redux/tree/master/examples/todomvc" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>
106116

107117
This is the classical [TodoMVC](http://todomvc.com/) example. It's here for the sake of comparison, but it covers the same points as the Todos example.
108118

109119
This example includes tests.
110120

111121
## Shopping Cart
112122

113-
Run the [Shopping Cart](https://github.com/reactjs/redux/tree/master/examples/shopping-cart) example:
123+
Run the [Shopping Cart](https://github.com/reduxjs/redux/tree/master/examples/shopping-cart) example:
114124

115125
```sh
116-
git clone https://github.com/reactjs/redux.git
126+
git clone https://github.com/reduxjs/redux.git
117127

118128
cd redux/examples/shopping-cart
119129
npm install
120130
npm start
121131
```
122132

123-
Or check out the [sandbox](https://codesandbox.io/s/github/reactjs/redux/tree/master/examples/shopping-cart).
133+
Or check out the [sandbox](https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/shopping-cart):
134+
135+
<iframe src="https://codesandbox.io/embed/github/reduxjs/redux/tree/master/examples/shopping-cart" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>
124136

125137
This example shows important idiomatic Redux patterns that become important as your app grows. In particular, it shows how to store entities in a normalized way by their IDs, how to compose reducers on several levels, and how to define selectors alongside the reducers so the knowledge about the state shape is encapsulated. It also demonstrates logging with [Redux Logger](https://github.com/fcomb/redux-logger) and conditional dispatching of actions with [Redux Thunk](https://github.com/gaearon/redux-thunk) middleware.
126138

127139
## Tree View
128140

129-
Run the [Tree View](https://github.com/reactjs/redux/tree/master/examples/tree-view) example:
141+
Run the [Tree View](https://github.com/reduxjs/redux/tree/master/examples/tree-view) example:
130142

131143
```sh
132-
git clone https://github.com/reactjs/redux.git
144+
git clone https://github.com/reduxjs/redux.git
133145

134146
cd redux/examples/tree-view
135147
npm install
136148
npm start
137149
```
138150

139-
Or check out the [sandbox](https://codesandbox.io/s/github/reactjs/redux/tree/master/examples/tree-view).
151+
Or check out the [sandbox](https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/tree-view):
152+
153+
<iframe src="https://codesandbox.io/embed/github/reduxjs/redux/tree/master/examples/tree-view" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>
140154

141155
This example demonstrates rendering a deeply nested tree view and representing its state in a normalized form so it is easy to update from reducers. Good rendering performance is achieved by the container components granularly subscribing only to the tree nodes that they render.
142156

143157
This example includes tests.
144158

145159
## Async
146160

147-
Run the [Async](https://github.com/reactjs/redux/tree/master/examples/async) example:
161+
Run the [Async](https://github.com/reduxjs/redux/tree/master/examples/async) example:
148162

149163
```sh
150-
git clone https://github.com/reactjs/redux.git
164+
git clone https://github.com/reduxjs/redux.git
151165

152166
cd redux/examples/async
153167
npm install
154168
npm start
155169
```
156170

157-
Or check out the [sandbox](https://codesandbox.io/s/github/reactjs/redux/tree/master/examples/async).
171+
Or check out the [sandbox](https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/async):
172+
173+
<iframe src="https://codesandbox.io/embed/github/reduxjs/redux/tree/master/examples/async" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>
158174

159175
This example includes reading from an asynchronous API, fetching data in response to user input, showing loading indicators, caching the response, and invalidating the cache. It uses [Redux Thunk](https://github.com/gaearon/redux-thunk) middleware to encapsulate asynchronous side effects.
160176

161177
## Universal
162178

163-
Run the [Universal](https://github.com/reactjs/redux/tree/master/examples/universal) example:
179+
Run the [Universal](https://github.com/reduxjs/redux/tree/master/examples/universal) example:
164180

165181
```sh
166-
git clone https://github.com/reactjs/redux.git
182+
git clone https://github.com/reduxjs/redux.git
167183

168184
cd redux/examples/universal
169185
npm install
@@ -174,20 +190,23 @@ This is a basic demonstration of [server rendering](../recipes/ServerRendering.m
174190

175191
## Real World
176192

177-
Run the [Real World](https://github.com/reactjs/redux/tree/master/examples/real-world) example:
193+
Run the [Real World](https://github.com/reduxjs/redux/tree/master/examples/real-world) example:
178194

179195
```sh
180-
git clone https://github.com/reactjs/redux.git
196+
git clone https://github.com/reduxjs/redux.git
181197

182198
cd redux/examples/real-world
183199
npm install
184200
npm start
185201
```
186202

187-
Or check out the [sandbox](https://codesandbox.io/s/github/reactjs/redux/tree/master/examples/real-world).
203+
Or check out the [sandbox](https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/real-world):
204+
205+
<iframe src="https://codesandbox.io/embed/github/reduxjs/redux/tree/master/examples/real-world" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>
188206

189207
This is the most advanced example. It is dense by design. It covers keeping fetched entities in a normalized cache, implementing a custom middleware for API calls, rendering partially loaded data, pagination, caching responses, displaying error messages, and routing. Additionally, it includes Redux DevTools.
190208

191209
## More Examples
192210

193-
You can find more examples in [Awesome Redux](https://github.com/xgrommx/awesome-redux).
211+
You can find more examples in the [Redux Apps and Examples](https://github.com/markerikson/redux-ecosystem-links/blob/master/apps-and-examples.md)
212+
page of the [Redux Addons Catalog](https://github.com/markerikson/redux-ecosystem-links).

examples/counter-vanilla/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Redux Counter Vanilla Example
2+
3+
This example does not require a build system or a view framework, and exists to show the raw Redux API used with ES5.
4+
5+
As Dan said [in the original PR for this example]():
6+
7+
> The new Counter Vanilla example is aimed to dispel the myth that Redux requires Webpack, React, hot reloading, sagas, action creators, constants, Babel, npm, CSS modules, decorators, fluent Latin, an Egghead subscription, a PhD, or an Exceeds Expectations O.W.L. level.
8+
>
9+
> Nope, it's just HTML, some artisanal `<script>` tags, and plain old DOM manipulation. Enjoy!
10+
11+
To try this example, just download the HTML file and open it in your browser.
12+
13+
(The `package.json` in this folder only exists to allow using this folder as a CodeSandbox embed, and is not required
14+
to run the HTML file.)

examples/counter-vanilla/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "counter-vanilla",
3+
"version": "1.0.0",
4+
"description": "A simple counter implemented using Redux",
5+
"main": "index.html",
6+
"scripts": {
7+
"start": "parcel index.html --open",
8+
"build": "parcel build index.html"
9+
},
10+
"dependencies": {},
11+
"devDependencies": {
12+
"@babel/core": "^7.2.0",
13+
"parcel-bundler": "^1.6.1"
14+
}
15+
}

0 commit comments

Comments
 (0)