Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit 0971f5d

Browse files
marconi1992ljharb
authored andcommitted
[New] export DATA_KEY and DATA_ID constants
1 parent 0a9fff9 commit 0971f5d

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,17 @@ function fromScript(attrs: Attributes): DeserializedData {}
377377
The inverse of `toScript`, this function runs on the browser and attempts to find and `JSON.parse` the contents of the server generated script.
378378
`attrs` is an object where the key will be a `data-key` to be placed on the element, and the value is the data attribute's value.
379379
380+
The `serialize` function uses the attributes `DATA_KEY` and `DATA_ID` to generate the data markup. They can be used in the `fromScript` function to get the serialized data.
381+
382+
```typescript
383+
import { DATA_KEY, DATA_ID } from 'hypernova'
384+
385+
fromScript({
386+
[DATA_KEY]: key,
387+
[DATA_ID]: id,
388+
});
389+
```
390+
380391
### Server
381392
382393
#### [createGetComponent](src/createGetComponent.js)

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,5 @@ hypernova.toScript = toScript;
9292
hypernova.fromScript = fromScript;
9393
hypernova.serialize = serialize;
9494
hypernova.load = load;
95+
hypernova.DATA_KEY = DATA_KEY;
96+
hypernova.DATA_ID = DATA_ID;

test/index-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { assert } from 'chai';
2+
import { DATA_KEY, DATA_ID } from '../lib';
3+
4+
describe('hypernova', () => {
5+
it('DATA_KEY constant should be importable', () => {
6+
assert.equal(DATA_KEY, 'hypernova-key');
7+
});
8+
9+
it('DATA_ID constant should be importable', () => {
10+
assert.equal(DATA_ID, 'hypernova-id');
11+
});
12+
});

0 commit comments

Comments
 (0)