-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from Telegram-Mini-Apps/bugfix/resize-problem
Fix a bug in SDK for Solid. Add local playground
- Loading branch information
Showing
13 changed files
with
210 additions
and
92 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@tma.js/bridge": patch | ||
--- | ||
|
||
Add logging in case resize event occured |
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,5 @@ | ||
--- | ||
"@tma.js/sdk-solid": patch | ||
--- | ||
|
||
Fix a bug with incorrect components events tracking |
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 @@ | ||
# Local Playground | ||
|
||
This application can be used by developers to test the code, written in the current monorepo. | ||
We created this playground to avoid writing the same code from one package to another, adding | ||
`index.html` and `vite.config.ts` files. | ||
|
||
## Usage | ||
|
||
1. First of all just import any code from the other packages. | ||
2. Run `pnpm run dev`. | ||
3. Open URL from the console. |
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,14 @@ | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" | ||
> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<script type="module" src="./index.ts"></script> | ||
</body> | ||
</html> |
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,8 @@ | ||
/* | ||
* You can import any code from the other folders in mono-repo. For example, you could | ||
* use this code: | ||
* | ||
* import { postEvent } from '../../packages/bridge/src/index.ts'; | ||
* | ||
* And test postEvent function here. | ||
* */ |
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 @@ | ||
{ | ||
"name": "local-playground", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"preview": "vite preview" | ||
} | ||
} |
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,26 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig", | ||
"compilerOptions": { | ||
"composite": false, | ||
"declaration": false, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"inlineSources": true, | ||
"isolatedModules": true, | ||
"lib": [ | ||
"esnext", | ||
"DOM" | ||
], | ||
"module": "ESNext", | ||
"moduleResolution": "NodeNext", | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"preserveWatchOutput": true, | ||
"resolveJsonModule": true, | ||
"skipLibCheck": true, | ||
"sourceMap": true, | ||
"strict": true, | ||
"target": "ESNext" | ||
}, | ||
"exclude": ["node_modules"] | ||
} |
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 |
---|---|---|
|
@@ -29,7 +29,8 @@ | |
"ts-jest": "^29.1.1", | ||
"tslib": "^2.6.0", | ||
"turbo": "^1.10.14", | ||
"typescript": "^5.1.6" | ||
"typescript": "^5.1.6", | ||
"vite": "^4.4.9" | ||
}, | ||
"packageManager": "[email protected]", | ||
"name": "monorepo", | ||
|
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,52 @@ | ||
import { Accessor, createEffect, createSignal, onCleanup } from 'solid-js'; | ||
import { SDKInitResult, SDKInitResultKey, SDKInitResultValue } from './types.js'; | ||
import { useInitResultValue } from './useInitResultValue.js'; | ||
|
||
interface Trackable { | ||
on: (event: any, ...args: any[]) => void; | ||
off: (event: any, ...args: any[]) => void; | ||
} | ||
|
||
type EventName<T extends Trackable> = T extends { | ||
on(event: infer E, ...args: any[]): any | ||
} ? E : never; | ||
|
||
type DynamicComponentKey = { | ||
[K in SDKInitResultKey]: SDKInitResultValue<K> extends Trackable ? K : never; | ||
}[SDKInitResultKey]; | ||
|
||
/** | ||
* Extracts value from the SDK init result by specified key and listens to its all specified | ||
* events, making the returned value to update. | ||
* @param initResult - SDK init result. | ||
* @param key - SDK init result key. | ||
* @param events - tracked events list. | ||
*/ | ||
export function useDynamicInitResultValue<K extends DynamicComponentKey>( | ||
initResult: Accessor<SDKInitResult>, | ||
key: K, | ||
events: EventName<SDKInitResultValue<K>>[], | ||
): Accessor<SDKInitResultValue<K>> { | ||
// Get original value from init result. | ||
const initResultValue = useInitResultValue(initResult, key); | ||
|
||
// Here we store value, which should always update it in case, some of its props | ||
// were changed/ | ||
const [value, setValue] = createSignal(initResultValue(), { equals: false }); | ||
|
||
createEffect(() => { | ||
const value = initResultValue(); | ||
const listener = () => { | ||
// We use prev => prev on purpose. This will make Solid sure, something inside | ||
// dynamic value changed. | ||
setValue(prev => prev); | ||
}; | ||
|
||
events.forEach(event => value.on(event, listener)); | ||
onCleanup(() => { | ||
events.forEach(event => value.off(event, listener)); | ||
}); | ||
}); | ||
|
||
return 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,14 @@ | ||
import { SDKInitResult, SDKInitResultKey, SDKInitResultValue } from './types.js'; | ||
import { Accessor, createMemo } from 'solid-js'; | ||
|
||
/** | ||
* Extracts value from the SDK init result by key. | ||
* @param result - init result accessor. | ||
* @param key - key to extract. | ||
*/ | ||
export function useInitResultValue<K extends SDKInitResultKey>( | ||
result: Accessor<SDKInitResult>, | ||
key: K | ||
): Accessor<SDKInitResultValue<K>> { | ||
return createMemo(() => result()[key]); | ||
} |
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
Oops, something went wrong.