Skip to content

Commit

Permalink
[New] export DATA_KEY and DATA_ID constants
Browse files Browse the repository at this point in the history
  • Loading branch information
marconi1992 authored and ljharb committed Aug 12, 2019
1 parent 0a9fff9 commit 0971f5d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,17 @@ function fromScript(attrs: Attributes): DeserializedData {}
The inverse of `toScript`, this function runs on the browser and attempts to find and `JSON.parse` the contents of the server generated script.
`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.
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.
```typescript
import { DATA_KEY, DATA_ID } from 'hypernova'

fromScript({
[DATA_KEY]: key,
[DATA_ID]: id,
});
```
### Server
#### [createGetComponent](src/createGetComponent.js)
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,5 @@ hypernova.toScript = toScript;
hypernova.fromScript = fromScript;
hypernova.serialize = serialize;
hypernova.load = load;
hypernova.DATA_KEY = DATA_KEY;
hypernova.DATA_ID = DATA_ID;
12 changes: 12 additions & 0 deletions test/index-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { assert } from 'chai';
import { DATA_KEY, DATA_ID } from '../lib';

describe('hypernova', () => {
it('DATA_KEY constant should be importable', () => {
assert.equal(DATA_KEY, 'hypernova-key');
});

it('DATA_ID constant should be importable', () => {
assert.equal(DATA_ID, 'hypernova-id');
});
});

0 comments on commit 0971f5d

Please sign in to comment.