-
Notifications
You must be signed in to change notification settings - Fork 687
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
[Doc] Targetables #2966
[Doc] Targetables #2966
Conversation
…nd add examples to reference docs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful work @jcalcaben. Love the way you have structured the docs.
I have provided minor change requests/questions. Let me know what you think of them?
* | ||
* @alias TargetableESModuleObject#add | ||
* @param {string} importString A static import declaration | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a @return
here?
* Adds a module or modules to the object using the `addImport()` function. | ||
* | ||
* @param {...string} args Static import declaration(s) | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a @return
here?
#### Extensions security | ||
|
||
For security reasons, PWA Studio restrict the scope of Targetable modifications within an extension's intercept file to source files in the extension package. | ||
This prevents third party extensions from making source code changes to a storefront project without the developer's knowledge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we elaborate on this? From an extension point of view, what is the targetable scope (its own files, storefront files, other extensions etc)?
Use this to reference the component's local name when adding custom code with Targetables. | ||
|
||
```jsx | ||
let Button = new SingleImportStatement("Button from './button'"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let Button = new SingleImportStatement("Button from './button'"); | |
let Button = new SingleImportStatement("import Button from './button'"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fun Fact: You can skip import
here and the class is smart enough to infer what you mean.
I'll add that note in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know. Nicee.
Pass in an import statement to the constructor to create a new `SingleImportStatement` object. | ||
|
||
```js | ||
const useQueryImport = new SingleImportStatement("import { useQuery } from '@apollo/react-hooks'"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useQueryImport
sounds like a hook/talon.
const useQueryImport = new SingleImportStatement("import { useQuery } from '@apollo/react-hooks'"); | |
const queryHookImport = new SingleImportStatement("import { useQuery } from '@apollo/react-hooks'"); |
Use the `changeBinding()` function to rename the variable bound to the imported object. | ||
|
||
```js | ||
const useQueryImport = new SingleImportStatement("import { useQuery } from '@apollo/react-hooks'"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const useQueryImport = new SingleImportStatement("import { useQuery } from '@apollo/react-hooks'"); | |
const queryHookImport = new SingleImportStatement("import { useQuery } from '@apollo/react-hooks'"); |
```js | ||
const useQueryImport = new SingleImportStatement("import { useQuery } from '@apollo/react-hooks'"); | ||
|
||
const useQueryImport2 = useQueryImport.changeBinding('useQuery2'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const useQueryImport2 = useQueryImport.changeBinding('useQuery2'); | |
const queryHookImport2 = useQueryImport.changeBinding('useQuery2'); |
|
||
#### Import statement limits | ||
|
||
The `addImport()` function can only handle import statements with a single binding. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's nice that you have mentioned this. Do we have a plan to handle/support multiple imports? If so, I guess it makes sense to mention that here for curious devs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not aware of any plans
'div className={pageClass}', | ||
'<span>appendJSX succeeded!</span>' | ||
) | ||
.addJSXClassName('div className={pageClass}', 'pageClass') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.addJSXClassName('div className={pageClass}', 'pageClass') | |
.addJSXClassName('div className={pageClass}', 'newClass') |
This class is available as a named import from `@magento/pwa-buildpack`. | ||
|
||
```js | ||
const { Targetables } = require('@magento/pwa-buildpack') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you mention that Targetables
and TargetableSet
are the same because nowhere in the following examples we are using TargetableSet
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful work. Approved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved latest commits.
Description
Create documentation for Targetables, this includes:
Related Issue
Closes PWA-796
Acceptance
Any core developer
Verification Stakeholders
Any core developer
Specification
Verification Steps
pwa-devdocs
project:cd pwa-devdocs
yarn develop
/pwa-buildpack/extensibility-framework/
/tutorials/targetables/
/pwa-buildpack/reference/targetables/TargetableSet/
Screenshots / Screen Captures (if appropriate)
Checklist