-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add option to revert to old hydrate (pre 4.9) behavior
- Loading branch information
1 parent
3b63b51
commit 6598c0c
Showing
8 changed files
with
130 additions
and
6 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
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
19 changes: 19 additions & 0 deletions
19
...ents-pages/fixtures/old-hydrate-no-create-no-input/components/child-component/index.marko
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,19 @@ | ||
class { | ||
onCreate() { | ||
if (typeof window !== 'undefined') { | ||
window.childCreateCalled = true; | ||
} | ||
} | ||
onInput() { | ||
if (typeof window !== 'undefined') { | ||
window.childInputCalled = true; | ||
} | ||
} | ||
onRender() { | ||
if (typeof window !== 'undefined') { | ||
window.childRenderCalled = true; | ||
} | ||
} | ||
} | ||
|
||
<div/> |
30 changes: 30 additions & 0 deletions
30
...nents-pages/fixtures/old-hydrate-no-create-no-input/components/test-component/index.marko
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,30 @@ | ||
class { | ||
onCreate(input) { | ||
if (typeof window !== 'undefined') { | ||
throw new Error('onCreate should not be called in the browser'); | ||
} | ||
this.state = { count:input.start } | ||
} | ||
onInput(input) { | ||
if (typeof window !== 'undefined') { | ||
throw new Error('onInput should not be called in the browser'); | ||
} | ||
this.state = { count:input.start } | ||
} | ||
increment() { | ||
this.state.count++; | ||
} | ||
onMount() { | ||
window.testComponent = this; | ||
} | ||
} | ||
|
||
<div> | ||
Hello <span.count>${state.count}</span>! | ||
<child-component key="child"/> | ||
</div> |
16 changes: 16 additions & 0 deletions
16
test/components-pages/fixtures/old-hydrate-no-create-no-input/template.marko
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,16 @@ | ||
<marko deprecated-no-create-or-input-lifecycle-for-top-level-hydrate /> | ||
|
||
<!DOCTYPE html> | ||
html lang="en" | ||
head | ||
meta charset="UTF-8" | ||
title -- Marko Components Tests | ||
body | ||
|
||
div id="test" | ||
div id="mocha" | ||
div id="testsTarget" | ||
|
||
<test-component start=10 /> | ||
|
||
init-components immediate |
25 changes: 25 additions & 0 deletions
25
test/components-pages/fixtures/old-hydrate-no-create-no-input/tests.js
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,25 @@ | ||
var path = require("path"); | ||
var expect = require("chai").expect; | ||
|
||
describe(path.basename(__dirname), function() { | ||
it("should mount, not call the onCreate/onInput methods and update", function() { | ||
var component = window.testComponent; | ||
|
||
expect(component.input.start).to.equal(10); | ||
expect(component.state.count).to.equal(10); | ||
expect(component.el.querySelector(".count").innerHTML).to.equal("10"); | ||
|
||
component.increment(); | ||
component.update(); | ||
|
||
expect(component.input.start).to.equal(10); | ||
expect(component.state.count).to.equal(11); | ||
expect(component.el.querySelector(".count").innerHTML).to.equal("11"); | ||
}); | ||
|
||
it("should still call all lifecycle methods on child components", function() { | ||
expect(window.childCreateCalled).to.equal(true); | ||
expect(window.childInputCalled).to.equal(true); | ||
expect(window.childRenderCalled).to.equal(true); | ||
}); | ||
}); |