-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `hydrate` function to `frint-react` * Update README
- Loading branch information
Showing
5 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* eslint-disable import/no-extraneous-dependencies, global-require */ | ||
import React from 'react'; | ||
|
||
import getMountableComponent from './components/getMountableComponent'; | ||
|
||
export default function hydrate(app, node) { | ||
const MountableComponent = getMountableComponent(app); | ||
const ReactDOM = require('react-dom'); | ||
|
||
return ReactDOM.hydrate(<MountableComponent />, node); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* eslint-disable import/no-extraneous-dependencies, func-names */ | ||
/* globals describe, document, it, beforeEach, resetDOM */ | ||
import { expect } from 'chai'; | ||
import React from 'react'; | ||
import { createApp } from 'frint'; | ||
|
||
import hydrate from './hydrate'; | ||
|
||
describe('frint-react › hydrate', function () { | ||
function TestComponent() { | ||
return <p>Hello World from TestApp!</p>; | ||
} | ||
|
||
const TestApp = createApp({ | ||
name: 'TestApp', | ||
providers: [ | ||
{ | ||
name: 'component', | ||
useValue: TestComponent, | ||
}, | ||
], | ||
}); | ||
|
||
beforeEach(function () { | ||
resetDOM(); | ||
}); | ||
|
||
it('hydrates app to DOM', function () { | ||
const app = new TestApp(); | ||
const rootEl = document.getElementById('root'); | ||
hydrate(app, rootEl); | ||
|
||
expect(rootEl.innerHTML) | ||
.to.contain('Hello World from TestApp!</p>'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* eslint-disable import/no-extraneous-dependencies, func-names */ | ||
/* global describe, it */ | ||
import { expect } from 'chai'; | ||
|
||
import index from './index'; | ||
|
||
describe('frint-react › index', function () { | ||
it('exports an object with the required keys', function () { | ||
expect(index).to.be.an('object'); | ||
expect(index).to.have.all.keys( | ||
'render', | ||
'hydrate', | ||
'streamProps', | ||
'isObservable', | ||
'getMountableComponent', | ||
'observe', | ||
'Region', | ||
'Provider', | ||
'RegionService', | ||
'ReactHandler', | ||
); | ||
}); | ||
}); |