-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
618f946
commit 3ba17dc
Showing
7 changed files
with
77 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "element-vir", | ||
"version": "16.0.3", | ||
"version": "16.1.0", | ||
"keywords": [ | ||
"custom", | ||
"web", | ||
|
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,43 @@ | ||
import {randomString} from '@augment-vir/browser'; | ||
import {assertTypeOf, typedAssertInstanceOf} from '@augment-vir/browser-testing'; | ||
import {assert, fixture as renderFixture} from '@open-wc/testing'; | ||
import {html} from '../../template-transforms/vir-html/vir-html'; | ||
import {defineElementNoInputs} from '../define-element-no-inputs'; | ||
import {perInstance} from './per-instance'; | ||
|
||
describe(perInstance.name, () => { | ||
it('allows host to be assigned to instance type', async () => { | ||
const MyElement = defineElementNoInputs({ | ||
tagName: `some-tag-${randomString()}`, | ||
stateInitStatic: { | ||
myPerInstanceProp: perInstance(() => ({stuff: 'hi'})), | ||
}, | ||
renderCallback({state}) { | ||
assertTypeOf(state.myPerInstanceProp).toEqualTypeOf<{stuff: string}>(); | ||
return state.myPerInstanceProp.stuff; | ||
}, | ||
}); | ||
|
||
const fixture = await renderFixture( | ||
html` | ||
<div> | ||
<${MyElement}></${MyElement}> | ||
<${MyElement}></${MyElement}> | ||
</div> | ||
`, | ||
); | ||
|
||
typedAssertInstanceOf(fixture, HTMLDivElement); | ||
|
||
const elements = Array.from(fixture.querySelectorAll(MyElement.tagName)); | ||
|
||
assert.lengthOf(elements, 2); | ||
|
||
typedAssertInstanceOf(elements[0], MyElement); | ||
typedAssertInstanceOf(elements[1], MyElement); | ||
assert.isFalse( | ||
elements[0].instanceState.myPerInstanceProp === | ||
elements[1].instanceState.myPerInstanceProp, | ||
); | ||
}); | ||
}); |
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,13 @@ | ||
import {ElementVirStateSetup} from './element-vir-state-setup'; | ||
|
||
/** | ||
* A state prop helper that sets up the given callback for each instance of the element that this | ||
* state is contained within. | ||
*/ | ||
export function perInstance<T>(creationCallback: () => T): T { | ||
const stateSetup: ElementVirStateSetup<T> = { | ||
_elementVirStateSetup: creationCallback, | ||
}; | ||
|
||
return stateSetup as T; | ||
} |
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