-
-
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
1c83169
commit e3e3b6b
Showing
10 changed files
with
51 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './components'; | ||
export { createElement, jsx } from './element'; | ||
export { createRef } from './ref'; | ||
export { render } from './render'; |
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 @@ | ||
export * from './ref'; |
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,12 @@ | ||
import { createRef } from './ref'; | ||
|
||
it('creates ref', () => { | ||
expect(createRef()).toEqual({ current: null }); | ||
}); | ||
|
||
it('sets ref', () => { | ||
type Type = 'value'; | ||
const ref = createRef<Type>(); | ||
ref.current = 'value'; | ||
expect(ref).toEqual({ current: 'value' }); | ||
}); |
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,12 @@ | ||
import type { Ref } from '../types'; | ||
|
||
/** | ||
* Creates a ref object which can contain arbitrary value. | ||
* | ||
* @returns - Creates an object with a single property `current` (initially set to `null`). | ||
*/ | ||
export function createRef<Type>(): Ref<Type> { | ||
return { | ||
current: null, | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,18 +1,25 @@ | ||
import type Phaser from 'phaser'; | ||
|
||
import { createRef } from '..'; | ||
import { attachRef } from './ref'; | ||
|
||
const gameObject = {} as Phaser.GameObjects.GameObject; | ||
|
||
it('attaches ref', () => { | ||
const mock = jest.fn(); | ||
expect(attachRef(gameObject, mock)); | ||
expect(mock).toBeCalledTimes(1); | ||
expect(mock).toBeCalledWith(gameObject); | ||
}); | ||
|
||
it('does not attach ref', () => { | ||
expect( | ||
attachRef(gameObject, null as unknown as Parameters<typeof attachRef>[1]), | ||
); | ||
}); | ||
|
||
it('attaches ref callback', () => { | ||
const callback = jest.fn(); | ||
expect(attachRef(gameObject, callback)); | ||
expect(callback).toBeCalledTimes(1); | ||
expect(callback).toBeCalledWith(gameObject); | ||
}); | ||
|
||
it('attaches ref object', () => { | ||
const ref = createRef<Phaser.GameObjects.GameObject>(); | ||
expect(attachRef(gameObject, ref)); | ||
expect(ref).toEqual({ current: gameObject }); | ||
}); |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './events'; | ||
export * from './phaser'; | ||
export * from './props'; | ||
export * from './ref'; | ||
export * from './utils'; |
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,3 @@ | ||
export interface Ref<Type> { | ||
current: Type | null; | ||
} |