Skip to content

Commit

Permalink
Merge branch 'master' into lifeless
Browse files Browse the repository at this point in the history
* master:
  Return decoyed elements where possible and reject on timeout
  Handle arbitrary number of decoy activations
  Give memoize a generic type
  Update dependencies
  Add environment detection
  2.1.2
  Don't assume we have a 2nd child node
  Include ABC Everyday application in getApplication docs.
  Clarify in README that decoy keys can be any [a-z] string, and that multiple decoys can be activated as a result of a single `requestDOMPermit`. Retain the `DECOY_KEYS` enum as a list of known keys but relax the type restrictions on key arguments from `DECOY_KEYS` to `string`.
  2.1.1
  Add ABC Everyday application to README
  Change PL's partial hostname for preview tier detection, to include feature branches which don't have "preview." in their hostnames
  Add Presentation Layer's ABC Everyday application
  2.1.0
  Update dependencies
  Add whenOdysseyLoaded promise
  • Loading branch information
drzax committed Mar 9, 2021
2 parents 759e89f + 6cb9c47 commit 360a9a8
Show file tree
Hide file tree
Showing 8 changed files with 7,288 additions and 3,840 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ node_modules
bin
dist
example/public/bundle.js
.envrc
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint
npm run test
9 changes: 9 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.log
.DS_Store
node_modules
*.test.*
.gitignore
.husky
.tsconfig.json
dist
.envrc
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ console.log(APPLICATIONS);
// P2: 'p2', // Phase 2
// PLA: 'pla', // Presentation Layer ABC AMP
// PLC: 'plc', // Presentation Layer Core
// PLE: 'ple', // Presentation Layer Everyday
// PLN: 'pln', // Presentation Layer News Web
// }
console.log(GENERATIONS);
Expand All @@ -69,7 +70,7 @@ console.log(TIERS);

### `getApplication(): string | null`

Return the environment's **application** (Phase 1 Mobile; Phase 1 Standard; Phase 2; Presentation Layer ABC AMP; Presentation Layer Core; Presentation Layer News Web) as a string value from the `APPLICATIONS` enum, or `null` if the application couldn't be determined.
Return the environment's **application** (Phase 1 Mobile; Phase 1 Standard; Phase 2; Presentation Layer ABC AMP; Presentation Layer Core; Presentation Layer Everyday; Presentation Layer News Web) as a string value from the `APPLICATIONS` enum, or `null` if the application couldn't be determined.

```js
import { APPLICATIONS, getApplication } from '@abcnews/env-utils';
Expand Down Expand Up @@ -123,20 +124,26 @@ This is advised before modifying the DOM on Presentation Layer generation applic

DOM modification is usually safe on older generation applications, but permits should be requested anyway, for the sake of consistency.

The `key` argument is used by Presentation Layer to activate its respective `<Decoy>` component.
The `key` argument is used by Presentation Layer to activate its respective `<Decoy>` components.

An optional `onRevokeHandler` argument can be passed, which will be called if Presentation Layer chooses to deactivate the `<Decoy>` and restore its orignal DOM.
An optional `onRevokeHandler` argument can be passed, which will be called if Presentation Layer chooses to deactivate `<Decoy>`s and restore their orignal DOM.

Note: `key` values may be any `[a-z]` string, but the Presentation Layer News Web application provides several pre-determined values, which this library exposes as `DECOY_KEYS`.

```js
import { DECOY_KEYS, requestDOMPermit } from '@abcnews/env-utils';

requestDOMPermit(DECOY_KEYS.PAGE, () => {
// It is no longer safe to modify the DOM tree below the <Decoy key="page"> PL compoonent
// It is no longer safe to modify the DOM tree below <Decoy listenKey="page"> PL compoonents
}).then(() => {
// It is now safe to modify the DOM tree below the <Decoy key="page"> PL compoonent
// It is now safe to modify the DOM tree below <Decoy listenKey="page"> PL compoonents
});
```

The returned promise resolves differently depending on the `GENERATION` on which it's running. On Presentation Layer sites the promise will resolve with an array of `HTMLElement` references for all the nodes where the decoy was activated. On prior generations, it will resolve with `true`.

The promise will be rejected after 5 seconds if all expected decoys haven't been activated. Additionally, the library will attempt to undo any successful activations by sending another request to PL to deactivate decoys with the given key.

## Authors

- Colin Gourlay ([[email protected]](mailto:[email protected]))
Loading

0 comments on commit 360a9a8

Please sign in to comment.