@graphcommerce/docs 6.1.1-canary.5 → 6.2.0-canary.7
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/CHANGELOG.md +4 -0
- package/contributing.md +1 -0
- package/framework/plugins-react.md +39 -12
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/contributing.md
CHANGED
|
@@ -98,6 +98,7 @@ need to sign the CLA once.
|
|
|
98
98
|
- Changeset is available
|
|
99
99
|
- Eslint must not report any errors in the changed files
|
|
100
100
|
- Eslint should not give any warnings in the changed files
|
|
101
|
+
- Bundle size should not increase significantly
|
|
101
102
|
- Lingui translations must be
|
|
102
103
|
[generated](https://www.graphcommerce.org/docs/framework/translations#generating-translation-files-with-all-translations)
|
|
103
104
|
and translated
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# Plugins
|
|
1
|
+
# Plugins GraphCommerce
|
|
2
2
|
|
|
3
|
-
GraphCommerce's
|
|
4
|
-
|
|
3
|
+
GraphCommerce's plugin system allows you to extend GraphCommerce's built-in
|
|
4
|
+
components or functions with your own logic.
|
|
5
5
|
|
|
6
6
|
- No runtime overhead: The plugin system is fully implemented in webpack and
|
|
7
7
|
- Easy plugin creation: Configuration should happen in the plugin file, not a
|
|
@@ -10,13 +10,30 @@ built-in components with your own logic.
|
|
|
10
10
|
|
|
11
11
|
## What is a plugin
|
|
12
12
|
|
|
13
|
-
A plugin is a way to modify React Components by wrapping them,
|
|
14
|
-
modify the code directly.
|
|
13
|
+
A plugin is a way to modify React Components or a Function by wrapping them,
|
|
14
|
+
without having to modify the code directly.
|
|
15
15
|
|
|
16
16
|
For the M2 people: Think of around plugins, but without configuration files and
|
|
17
17
|
no performance penalty.
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
GraphCommerce has two kinds of plugins, React Component plugins and Function
|
|
20
|
+
|
|
21
|
+
React Component plugins, which can be used to:
|
|
22
|
+
|
|
23
|
+
- Pass props to components
|
|
24
|
+
- Place your own components before the original component
|
|
25
|
+
- Place your own components after the original component
|
|
26
|
+
- Skip rendering of the original component conditionally
|
|
27
|
+
|
|
28
|
+
Function plugins, which can be used to:
|
|
29
|
+
|
|
30
|
+
- Call a function before the original function
|
|
31
|
+
- Call a function after the original function
|
|
32
|
+
- Modify the return value of a function
|
|
33
|
+
- Modify the arguments of a function
|
|
34
|
+
- Skip calling the original function conditionally
|
|
35
|
+
|
|
36
|
+
## How do I write a React Component plugin?
|
|
20
37
|
|
|
21
38
|
In this example we're going to add some text to list items, just like the text
|
|
22
39
|
‘BY GC’ that can seen in the demo on
|
|
@@ -26,14 +43,14 @@ In this example we're going to add some text to list items, just like the text
|
|
|
26
43
|
contents:
|
|
27
44
|
|
|
28
45
|
```tsx
|
|
29
|
-
import type {
|
|
30
|
-
import type {
|
|
46
|
+
import type { ProductListItem } from '@graphcommerce/magento-product'
|
|
47
|
+
import type { ReactPlugin } from '@graphcommerce/next-config'
|
|
31
48
|
import { Typography } from '@mui/material'
|
|
32
49
|
|
|
33
50
|
export const component = 'ProductListItem' // Component to extend, required
|
|
34
51
|
export const exported = '@graphcommerce/magento-product' // Location where the component is exported, required
|
|
35
52
|
|
|
36
|
-
|
|
53
|
+
const ListPlugin: ReactPlugin<typeof ProductListItem> = (props) => {
|
|
37
54
|
// Prev in this case is ProductListItem, you should be able to see this if you log it.
|
|
38
55
|
const { Prev, ...rest } = props
|
|
39
56
|
return (
|
|
@@ -47,7 +64,7 @@ In this example we're going to add some text to list items, just like the text
|
|
|
47
64
|
/>
|
|
48
65
|
)
|
|
49
66
|
}
|
|
50
|
-
export const Plugin =
|
|
67
|
+
export const Plugin = ListPlugin // An export with the name Plugin, required
|
|
51
68
|
```
|
|
52
69
|
|
|
53
70
|
2. Trigger the 'interceptor generation' so GraphCommerce knows of the existence
|
|
@@ -56,10 +73,20 @@ In this example we're going to add some text to list items, just like the text
|
|
|
56
73
|
and save the file
|
|
57
74
|
|
|
58
75
|
If everything went as expected you should see `Plugin!` below the product
|
|
59
|
-
name.
|
|
76
|
+
name. If that doesn't work try restarting the dev server.
|
|
60
77
|
|
|
61
78
|
3. Happy programming!
|
|
62
79
|
|
|
80
|
+
4. You can enable debug mode in your graphcommerce.config.js:
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
const config = {
|
|
84
|
+
debug: {
|
|
85
|
+
pluginStatus: true,
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
63
90
|
## How does it work?
|
|
64
91
|
|
|
65
92
|
After the creation of the plugin file GraphCommerce will create an interceptor
|
|
@@ -108,7 +135,7 @@ When opening the React debugger you can see the plugin wrapped.
|
|
|
108
135
|
|
|
109
136
|
GraphCommerce uses a custom Webpack plugin to load the plugins. The plugin does
|
|
110
137
|
a glob search for plugin folders in each GraphCommerce related pacakge:
|
|
111
|
-
`${packageLocation}/plugins/**/*.tsx`
|
|
138
|
+
`${packageLocation}/plugins/**/*.{ts|tsx}`
|
|
112
139
|
|
|
113
140
|
Package locations are the root and all packages with `graphcommerce` in the name
|
|
114
141
|
(This means all `@graphcommerce/*` packages and
|
package/package.json
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"name": "@graphcommerce/docs",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/docs",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce/docs",
|
|
5
|
-
"version": "6.
|
|
5
|
+
"version": "6.2.0-canary.7",
|
|
6
6
|
"sideEffects": true,
|
|
7
7
|
"devDependencies": {
|
|
8
|
-
"@graphcommerce/prettier-config-pwa": "6.
|
|
8
|
+
"@graphcommerce/prettier-config-pwa": "6.2.0-canary.7"
|
|
9
9
|
},
|
|
10
10
|
"prettier": "@graphcommerce/prettier-config-pwa"
|
|
11
11
|
}
|