@thoughtbot/superglue 0.51.1 → 0.52.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ <div align="center" style="padding: 30px 0px 20px 0px;">
2
+ <img src="https://thoughtbot.github.io/superglue/images/superglue.svg" data-origin="images/superglue.svg" alt="Logo" width=250>
3
+ </div>
4
+
1
5
  # Superglue
2
6
 
3
7
  Use classic Rails to build rich React Redux applications with **NO APIs** and
@@ -5,11 +9,11 @@ Use classic Rails to build rich React Redux applications with **NO APIs** and
5
9
 
6
10
  [![Build Status](https://circleci.com/gh/thoughtbot/superglue.svg?style=shield)](https://circleci.com/gh/thoughtbot/superglue)
7
11
 
8
- Superglue makes React and Redux equally as productive as Hotwire, Turbo and
9
- Stimulus. Its inspired by Turbolinks and designed to feel like a natural
10
- extension of Rails. Enjoy the benefits of Redux state management and React
11
- components without giving up the productivity of Rails form helpers, UJS,
12
- tag helpers, flash, cookie auth, and more.
12
+ Superglue makes React and Redux as productive as Hotwire, Turbo and Stimulus.
13
+ Its inspired by Turbolinks and designed to feel like a natural extension of
14
+ Rails. Enjoy the benefits of Redux state management and React components
15
+ without giving up the productivity of Rails form helpers, UJS, tag helpers,
16
+ flash, cookie auth, and more.
13
17
 
14
18
  ## Caution
15
19
 
@@ -30,22 +34,22 @@ The end result would be something like this:
30
34
  ![No Apis](https://thoughtbot.github.io/superglue/images/no_apis.png)
31
35
 
32
36
  ### Powered by Classic Rails
33
- Superglue is mostly classic Rails. Features like the flash, cookie auth, and URL
37
+ Superglue leans on Rails. Features like the flash, cookie auth, and URL
34
38
  helpers continue to be useful. Here's a look at the directory structure of a
35
39
  typical Rails application with Superglue.
36
40
 
37
- ```
38
- MyRailsApp/
39
- app/
40
- views/
41
- dashboard/
42
- index.html.erb <- Mostly empty. Where `index.json.props` gets rendered as initial state
43
- index.js <- Your page component, will receive `index.json.props`. Gets packaged with application.js
44
- index.json.props <- will also respond to `.json` requests
41
+ ```treeview
42
+ app/
43
+ |-- controllers/
44
+ |-- views/
45
+ | |-- dashboard/
46
+ | | |-- index.js # The React page component
47
+ | | |-- index.json.props # The json for the page component
48
+ | | |-- index.html.erb
45
49
  ```
46
50
 
47
51
  ### PropsTemplate
48
- Powering these JSON responses is PropsTemplate, a traversable JSON templating DSL
52
+ Powering the JSON responses is PropsTemplate, a digable JSON templating DSL
49
53
  inspired by JBuilder. With PropsTemplate you can specify a path of the node you
50
54
  want, and PropsTemplate will walk the tree to it, skipping the execution of nodes
51
55
  that don't match the keypath.
@@ -61,36 +65,38 @@ A popular ask of SPAs is page-to-page navigation without reloading. This is
61
65
  easily done with Superglue's own UJS attributes inspired by Turbolinks:
62
66
 
63
67
  ```jsx
64
- <a href='/posts' data-sg-visit={true} />
68
+ <a href='/posts' data-sg-visit />
65
69
  ```
66
70
 
67
71
  The above will request for `/posts` with an `accept` of `application/json`, and
68
72
  when the client receives the response, swap out the current component for the
69
73
  component the response asks for, and `pushState` on history.
70
74
 
71
- #### Partial updates
72
- Some features rely on updating some parts of the existing page. In
73
- addition to `data-sg-visit` and it's equivalent `this.props.visit`, Superglue
74
- also provides `data-sg-remote` or `this.props.remote`, which you can use to
75
- update parts of your page in async fashion without changing `window.history`.
76
75
 
77
- Imagine having to implement search, where you enter some text, hit enter, and
78
- results would show without reloading the screen. In traditional applications,
79
- you may need a new controller, routes, a discussion over versioning, JSON
80
- serializer, plenty of new JS code, etc.
76
+ #### Easy Partial updates
77
+ Some features rely on updating some parts of the existing page. Imagine
78
+ implementing type-ahead search. In traditional applications, you may need a new
79
+ controller, routes, a discussion over versioning, JSON serializer, plenty of
80
+ new JS code, etc.
81
81
 
82
82
  ![haircuts](https://thoughtbot.github.io/superglue/images/haircuts.png)
83
83
 
84
- With Superglue, this can be done in one line:
84
+ With Superglue, this can be done with a simple `onChange`
85
85
 
86
- ```javascript
87
- this.props.remote('/dashboard?qry=haircut&props_at=data.header.search')
86
+ ```js
87
+ const onChange = (e) => (
88
+ remote(`/dashboard?qry=${e.target.value}&props_at=data.header.search`)}
89
+ )
88
90
  ```
89
91
 
90
- The above will make a request to `/dashboard?qry=haircut`, walk your props to
91
- the `data.header.search` node, return it in the response, and immutably graft it
92
- in the exact same path on the redux store before finally letting React
93
- re-render.
92
+ ?> `remote` and `visit` is a thunk [passed] to every page component.
93
+
94
+ [passed]: ./navigation.md
95
+
96
+ With `props_at`, the above will make a request to `/dashboard?qry=haircut`,
97
+ dig your template for the `data.header.search` node, return it in the response,
98
+ and immutably graft it in the exact same path on the redux store before finally
99
+ letting React re-render.
94
100
 
95
101
  For more on what you can do, check out our documentation.
96
102
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thoughtbot/superglue",
3
- "version": "0.51.1",
3
+ "version": "0.52.1",
4
4
  "description": "Use a vanilla Rails with React and Redux",
5
5
  "repository": {
6
6
  "type": "git",
@@ -114,10 +114,6 @@ function atKey(node, key) {
114
114
  throw new KeyPathError("Expected to find an Array when using the key: " + key);
115
115
  }
116
116
 
117
- if (isObject(node) && !Object.prototype.hasOwnProperty.call(node, key)) {
118
- throw new KeyPathError("Expected to find key: " + key + " in object " + JSON.stringify(node));
119
- }
120
-
121
117
  if (Array.isArray(node) && id) {
122
118
  var child;
123
119