@potok-web-framework/core 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/dist/block.d.ts +17 -0
  2. package/dist/bootstrap-app.d.ts +8 -0
  3. package/dist/client-only.d.ts +3 -0
  4. package/dist/client.mjs +133 -0
  5. package/dist/constants-BOAOReQ3.mjs +26 -0
  6. package/dist/constants.d.ts +2 -0
  7. package/dist/context.d.ts +12 -0
  8. package/dist/detect-child.d.ts +6 -0
  9. package/dist/error-boundary.d.ts +5 -0
  10. package/dist/exports/client.d.ts +1 -0
  11. package/dist/exports/hmr.d.ts +1 -0
  12. package/dist/exports/index.d.ts +14 -0
  13. package/dist/exports/jsx-runtime.d.ts +4 -0
  14. package/dist/exports/server.d.ts +1 -0
  15. package/dist/fragment-BahmURhz.mjs +17 -0
  16. package/dist/fragment.d.ts +4 -0
  17. package/dist/hmr/hmr-dev.d.ts +9 -0
  18. package/dist/hmr/register-component.d.ts +2 -0
  19. package/dist/hmr/registered-component.d.ts +23 -0
  20. package/dist/hmr/registry.d.ts +12 -0
  21. package/dist/hmr/types.d.ts +4 -0
  22. package/dist/hmr/utils.d.ts +3 -0
  23. package/dist/hmr.mjs +42 -0
  24. package/dist/html-element-Cm0RtMkT.mjs +42 -0
  25. package/dist/html-element.d.ts +6 -0
  26. package/dist/index.mjs +199 -0
  27. package/dist/jsx-runtime.mjs +10 -0
  28. package/dist/jsx-types.d.ts +11 -0
  29. package/dist/lazy.d.ts +7 -0
  30. package/dist/lib-context-reader.d.ts +5 -0
  31. package/dist/lib-scripts.d.ts +2 -0
  32. package/dist/lifecycle-4vjEuXGy.mjs +57 -0
  33. package/dist/lifecycle.d.ts +8 -0
  34. package/dist/list.d.ts +9 -0
  35. package/dist/portal-CbcYOHLv.mjs +44 -0
  36. package/dist/portal.d.ts +10 -0
  37. package/dist/prop-types.d.ts +939 -0
  38. package/dist/ref.d.ts +6 -0
  39. package/dist/render-to-dom.d.ts +8 -0
  40. package/dist/render-to-string.d.ts +2 -0
  41. package/dist/server-node.d.ts +10 -0
  42. package/dist/server.mjs +1192 -0
  43. package/dist/show.d.ts +6 -0
  44. package/dist/signals.d.ts +32 -0
  45. package/dist/store.d.ts +26 -0
  46. package/dist/text.d.ts +5 -0
  47. package/dist/types.d.ts +39 -0
  48. package/dist/utils-CAe_kbSH.mjs +345 -0
  49. package/dist/utils.d.ts +11 -0
  50. package/package.json +7 -2
  51. package/CHANGELOG.md +0 -7
  52. package/bun.lock +0 -25
  53. package/src/block.ts +0 -102
  54. package/src/bootstrap-app.ts +0 -115
  55. package/src/client-only.ts +0 -17
  56. package/src/constants.ts +0 -27
  57. package/src/context.ts +0 -85
  58. package/src/detect-child.ts +0 -21
  59. package/src/error-boundary.ts +0 -51
  60. package/src/exports/client.ts +0 -1
  61. package/src/exports/hmr.ts +0 -1
  62. package/src/exports/index.ts +0 -21
  63. package/src/exports/jsx-runtime.ts +0 -4
  64. package/src/exports/server.ts +0 -1
  65. package/src/fragment.ts +0 -28
  66. package/src/global.dev.d.ts +0 -12
  67. package/src/hmr/hmr-dev.ts +0 -10
  68. package/src/hmr/register-component.ts +0 -109
  69. package/src/hmr/registered-component.ts +0 -59
  70. package/src/hmr/registry.ts +0 -78
  71. package/src/hmr/types.ts +0 -6
  72. package/src/hmr/utils.ts +0 -20
  73. package/src/html-element.ts +0 -95
  74. package/src/jsx-types.ts +0 -13
  75. package/src/lazy.ts +0 -44
  76. package/src/lib-context-reader.ts +0 -33
  77. package/src/lib-scripts.ts +0 -8
  78. package/src/lifecycle.ts +0 -44
  79. package/src/list.ts +0 -175
  80. package/src/portal.ts +0 -101
  81. package/src/prop-types.ts +0 -1165
  82. package/src/ref.ts +0 -11
  83. package/src/render-to-dom.ts +0 -325
  84. package/src/render-to-string.ts +0 -65
  85. package/src/server-node.ts +0 -98
  86. package/src/show.ts +0 -46
  87. package/src/signals.ts +0 -323
  88. package/src/store.ts +0 -68
  89. package/src/text.ts +0 -35
  90. package/src/types.ts +0 -69
  91. package/src/utils.ts +0 -118
  92. package/tests/signals.test.ts +0 -403
  93. package/tsconfig.json +0 -17
  94. package/vite.config.ts +0 -21
@@ -1,115 +0,0 @@
1
- import { CLIENT_ENTRY_FILE_NAME } from './constants'
2
- import { PortalIn } from './portal'
3
- import { renderToString } from './render-to-string'
4
- import path from 'path'
5
- import type { PotokElement } from './types'
6
- import { toFetchResponse, toReqRes } from 'fetch-to-node'
7
- import { fragment } from './fragment'
8
- import { htmlElement } from './html-element'
9
-
10
- type App = (request: Request) => PotokElement
11
- type BootstrapAppOptions = {
12
- app: App
13
- port?: number
14
- }
15
-
16
- let serverStarted = false
17
- let setApp: (app: App) => void = () => {}
18
-
19
- export function bootstrapApp(options: BootstrapAppOptions) {
20
- const port = options.port ?? 3000
21
-
22
- if (!serverStarted) {
23
- let currentApp = options.app
24
-
25
- setApp = (app: App) => {
26
- currentApp = app
27
- }
28
-
29
- Bun.serve({
30
- async fetch(request) {
31
- const url = new URL(request.url)
32
- const pathname = decodeURIComponent(url.pathname)
33
-
34
- if (process.env.NODE_ENV === 'development') {
35
- const viteServer = __POTOK_DEV__?.vite
36
-
37
- if (viteServer) {
38
- const response = await new Promise<Response | undefined>(
39
- (resolve) => {
40
- const { req, res } = toReqRes(request)
41
-
42
- const originalEnd = res.end.bind(res)
43
-
44
- res.end = (...args: any[]) => {
45
- const response = originalEnd(...args)
46
- resolve(toFetchResponse(response))
47
- return response
48
- }
49
-
50
- viteServer.middlewares(req, res, () => {
51
- resolve(undefined)
52
- })
53
- },
54
- )
55
-
56
- if (response) {
57
- return response
58
- }
59
- }
60
- }
61
-
62
- if (/\.[a-z0-9]+$/i.test(pathname)) {
63
- const file = Bun.file(path.join(process.cwd(), 'dist', pathname))
64
- if (await file.exists()) {
65
- return new Response(file, {
66
- headers: { 'Content-Type': file.type },
67
- })
68
- }
69
- }
70
-
71
- const html = await renderToString(
72
- fragment({
73
- children: [
74
- currentApp(request),
75
- PortalIn({
76
- name: 'lib-scripts',
77
- children: __POTOK_DEV__
78
- ? fragment({
79
- children: [
80
- htmlElement({
81
- tag: 'script',
82
- type: 'module',
83
- src: '/@vite/client',
84
- }),
85
- htmlElement({
86
- tag: 'script',
87
- type: 'module',
88
- src: '/src/client.ts',
89
- }),
90
- ],
91
- })
92
- : htmlElement({
93
- tag: 'script',
94
- type: 'module',
95
- src: `/${CLIENT_ENTRY_FILE_NAME}.js`,
96
- }),
97
- }),
98
- ],
99
- }),
100
- )
101
-
102
- return new Response(html, {
103
- headers: { 'Content-Type': 'text/html; charset=utf-8' },
104
- })
105
- },
106
- port,
107
- })
108
-
109
- serverStarted = true
110
-
111
- console.log(`Приложение запущено на порте ${port}`)
112
- } else {
113
- setApp(options.app)
114
- }
115
- }
@@ -1,17 +0,0 @@
1
- import { LibContextReader } from './lib-context-reader'
2
- import { Show } from './show'
3
- import { PotokElement, WithChildren } from './types'
4
-
5
- export type ClientOnlyProps = WithChildren<{}>
6
-
7
- export function ClientOnly(props: ClientOnlyProps): PotokElement {
8
- return LibContextReader({
9
- children: (context) =>
10
- Show({
11
- get when() {
12
- return !context.isServer && !context.isHydrating
13
- },
14
- children: props.children,
15
- }),
16
- })
17
- }
package/src/constants.ts DELETED
@@ -1,27 +0,0 @@
1
- export const HTML_ELEMENT_STYLE_PX_PROPERTIES = new Set([
2
- 'width',
3
- 'height',
4
- 'top',
5
- 'left',
6
- 'right',
7
- 'bottom',
8
- 'margin',
9
- 'marginTop',
10
- 'marginBottom',
11
- 'marginLeft',
12
- 'marginRight',
13
- 'padding',
14
- 'paddingTop',
15
- 'paddingBottom',
16
- 'paddingLeft',
17
- 'paddingRight',
18
- 'fontSize',
19
- 'borderWidth',
20
- 'borderRadius',
21
- 'maxWidth',
22
- 'minWidth',
23
- 'maxHeight',
24
- 'minHeight',
25
- ])
26
-
27
- export const CLIENT_ENTRY_FILE_NAME = 'client'
package/src/context.ts DELETED
@@ -1,85 +0,0 @@
1
- import { LibBlock } from './block'
2
- import type {
3
- LibContext,
4
- MaybeArray,
5
- PotokElement,
6
- WithChildren,
7
- } from './types'
8
- import { mergeContext, normalizeArray, normalizeChildren } from './utils'
9
-
10
- type ContextProviderProps<Value extends Record<string, unknown>> =
11
- WithChildren<{
12
- value: Value
13
- }>
14
-
15
- class ContextProvider<Value extends Record<string, unknown>> extends LibBlock {
16
- constructor(
17
- readonly props: ContextProviderProps<Value>,
18
- key: symbol,
19
- readonly context: LibContext
20
- ) {
21
- super()
22
-
23
- normalizeChildren(props.children).forEach((childCreator, index) => {
24
- this.children.push(
25
- childCreator(
26
- mergeContext(context, {
27
- parentBlock: this,
28
- index,
29
- contexts: {
30
- [key]: props.value,
31
- },
32
- })
33
- )
34
- )
35
- })
36
- }
37
- }
38
-
39
- type ContextConsumerProps<Value extends Record<string, unknown>> = {
40
- children: MaybeArray<(value: Value) => PotokElement>
41
- }
42
-
43
- class ContextConsumer<Value extends Record<string, unknown>> extends LibBlock {
44
- constructor(
45
- readonly props: ContextConsumerProps<Value>,
46
- key: symbol,
47
- readonly context: LibContext
48
- ) {
49
- super()
50
-
51
- const value = context.contexts[key]
52
-
53
- if (!value) {
54
- throw new Error(`Контекст не найден`)
55
- }
56
-
57
- normalizeArray(props.children).forEach((childCreator, index) => {
58
- this.children.push(
59
- childCreator(value as Value)(
60
- mergeContext(context, {
61
- parentBlock: this,
62
- index,
63
- })
64
- )
65
- )
66
- })
67
- }
68
- }
69
-
70
- export function createContext<Value extends Record<string, unknown>>() {
71
- const key = Symbol('context')
72
-
73
- return {
74
- provider(props: ContextProviderProps<Value>): PotokElement {
75
- return function (context: LibContext) {
76
- return new ContextProvider(props, key, context)
77
- }
78
- },
79
- reader(props: ContextConsumerProps<Value>): PotokElement {
80
- return function (context: LibContext) {
81
- return new ContextConsumer(props, key, context)
82
- }
83
- },
84
- }
85
- }
@@ -1,21 +0,0 @@
1
- import { text } from './text'
2
- import { Child } from './types'
3
-
4
- type DetectChildProps = {
5
- readonly value: Child
6
- }
7
-
8
- export function detectChild(props: DetectChildProps): Child {
9
- const value = props.value
10
- const type = typeof value
11
-
12
- if (type === 'string' || type === 'number' || type === 'boolean') {
13
- return text({
14
- get text() {
15
- return props.value
16
- },
17
- })
18
- }
19
-
20
- return value
21
- }
@@ -1,51 +0,0 @@
1
- import { LibBlock } from './block'
2
- import type { LibContext, PotokElement, WithChildren } from './types'
3
- import { mergeContext, normalizeChildren } from './utils'
4
-
5
- export type ErrorBoundaryProps = WithChildren<{
6
- onError?: (error: Error) => void
7
- }>
8
-
9
- class ErrorBoundaryClass extends LibBlock {
10
- constructor(
11
- readonly props: ErrorBoundaryProps,
12
- readonly context: LibContext
13
- ) {
14
- super()
15
-
16
- try {
17
- normalizeChildren(props.children).forEach((childCreator, index) => {
18
- this.children.push(
19
- childCreator(
20
- mergeContext(context, {
21
- parentBlock: this,
22
- index,
23
- })
24
- )
25
- )
26
- })
27
- } catch (error) {
28
- props.onError?.(this.buildError(error))
29
- }
30
- }
31
-
32
- override unmount() {
33
- try {
34
- super.unmount()
35
- } catch (error) {
36
- this.props.onError?.(this.buildError(error))
37
- }
38
- }
39
-
40
- private buildError(error: unknown) {
41
- return error instanceof Error
42
- ? error
43
- : new Error(typeof error === 'string' ? error : 'Unknown error')
44
- }
45
- }
46
-
47
- export function ErrorBoundary(props: ErrorBoundaryProps): PotokElement {
48
- return function (context: LibContext) {
49
- return new ErrorBoundaryClass(props, context)
50
- }
51
- }
@@ -1 +0,0 @@
1
- export { renderToDOM } from '../render-to-dom'
@@ -1 +0,0 @@
1
- export { registerComponent } from '../hmr/register-component'
@@ -1,21 +0,0 @@
1
- export { ClientOnly } from '../client-only'
2
- export { ErrorBoundary } from '../error-boundary'
3
- export { Lazy } from '../lazy'
4
- export { LibContextReader } from '../lib-context-reader'
5
- export { LibScripts } from '../lib-scripts'
6
- export { Lifecycle } from '../lifecycle'
7
- export { List } from '../list'
8
- export { PortalIn, PortalOut } from '../portal'
9
- export { createElementReference } from '../ref'
10
- export { Show } from '../show'
11
- export {
12
- createSignal,
13
- createEffect,
14
- batch,
15
- untrack,
16
- deepTrack,
17
- getSignal,
18
- } from '../signals'
19
- export { createStore } from '../store'
20
- export type { PotokElement, WithChildren } from '../types'
21
- export type * from '../jsx-types.ts'
@@ -1,4 +0,0 @@
1
- export { fragment } from '../fragment'
2
- export { htmlElement } from '../html-element'
3
- export { text } from '../text'
4
- export { detectChild } from '../detect-child'
@@ -1 +0,0 @@
1
- export { bootstrapApp } from '../bootstrap-app'
package/src/fragment.ts DELETED
@@ -1,28 +0,0 @@
1
- import { LibBlock } from './block'
2
- import type { LibContext, PotokElement, WithChildren } from './types'
3
- import { mergeContext, normalizeChildren } from './utils'
4
-
5
- type FragmentProps = WithChildren<{}>
6
-
7
- class FragmentClass extends LibBlock {
8
- constructor(readonly props: FragmentProps, readonly context: LibContext) {
9
- super()
10
-
11
- normalizeChildren(props.children).forEach((childCreator, index) => {
12
- this.children.push(
13
- childCreator(
14
- mergeContext(context, {
15
- parentBlock: this,
16
- index,
17
- })
18
- )
19
- )
20
- })
21
- }
22
- }
23
-
24
- export function fragment(props: FragmentProps): PotokElement {
25
- return function (context: LibContext) {
26
- return new FragmentClass(props, context)
27
- }
28
- }
@@ -1,12 +0,0 @@
1
- import type { ViteDevServer } from 'vite'
2
- import { PotokElement } from './types'
3
-
4
- declare global {
5
- const __POTOK_DEV__:
6
- | {
7
- vite: ViteDevServer
8
- }
9
- | undefined
10
- }
11
-
12
- export {}
@@ -1,10 +0,0 @@
1
- import { CachedInstanceState } from './registered-component'
2
- import { HMRRegistry } from './registry'
3
-
4
- export const HMR_DEV = {
5
- registry: new HMRRegistry(),
6
- currentInstance: null as {
7
- states: CachedInstanceState[]
8
- stateIndex: number
9
- } | null,
10
- }
@@ -1,109 +0,0 @@
1
- import { fragment } from '../fragment'
2
- import { Lifecycle } from '../lifecycle'
3
- import { LibContextReader } from '../lib-context-reader'
4
- import { Show } from '../show'
5
- import { createSignal } from '../signals'
6
- import { Component, ComponentProps, LibContext, PotokElement } from '../types'
7
- import { getComponentInstanceId, isWindowDefined } from './utils'
8
- import { HMR_DEV } from './hmr-dev'
9
-
10
- export function registerComponent<Props extends ComponentProps>(
11
- component: (props: Props) => PotokElement,
12
- moduleId: string,
13
- componentId: string,
14
- ): Component<Props> {
15
- if (!isWindowDefined()) {
16
- return component
17
- }
18
-
19
- const registeredComponent = HMR_DEV.registry.addComponent(
20
- moduleId,
21
- componentId,
22
- component,
23
- )
24
- HMR_DEV.registry.notifyComponentUpdate(moduleId, componentId)
25
-
26
- function renderComponent(
27
- props: Props,
28
- context: LibContext,
29
- ignoreCache = false,
30
- ) {
31
- const instanceId = getComponentInstanceId(context)
32
- const cachedInstance = registeredComponent.getCachedInstance(instanceId)
33
-
34
- if (!ignoreCache && cachedInstance) {
35
- return cachedInstance.element
36
- }
37
-
38
- HMR_DEV.currentInstance = {
39
- states: cachedInstance ? cachedInstance.states : [],
40
- stateIndex: 0,
41
- }
42
-
43
- const element = registeredComponent.component(props)
44
- registeredComponent.addCachedInstance(
45
- instanceId,
46
- element,
47
- HMR_DEV.currentInstance.states,
48
- )
49
- HMR_DEV.currentInstance = null
50
-
51
- return element
52
- }
53
-
54
- return (props: Props) => {
55
- return LibContextReader({
56
- children(context) {
57
- const value = createSignal({
58
- element: renderComponent(props, context) as PotokElement | null,
59
- })
60
-
61
- const instanceId = getComponentInstanceId(context)
62
-
63
- return Lifecycle({
64
- onMounted() {
65
- const unsubscribe = HMR_DEV.registry.subscribeToComponent(
66
- moduleId,
67
- componentId,
68
- () => {
69
- value.element = null
70
- value.element = renderComponent(props, context, true)
71
- },
72
- )
73
-
74
- registeredComponent.unmarkInstanceAsRemovable(instanceId)
75
-
76
- return () => {
77
- unsubscribe()
78
-
79
- registeredComponent.markInstanceAsRemovable(instanceId)
80
-
81
- setTimeout(() => {
82
- const cachedInstance =
83
- registeredComponent.getCachedInstance(instanceId)
84
-
85
- if (cachedInstance?.isRemovable) {
86
- registeredComponent.removeCachedInstance(instanceId)
87
- }
88
- })
89
- }
90
- },
91
- children: [
92
- Show({
93
- get when() {
94
- return value.element !== null
95
- },
96
- children: [
97
- fragment({
98
- get children() {
99
- return [value.element!]
100
- },
101
- }),
102
- ],
103
- }),
104
- ],
105
- })
106
- },
107
- })
108
- }
109
- }
@@ -1,59 +0,0 @@
1
- import { Component, PotokElement } from '../types'
2
- import { HMRSubscriber } from './types'
3
-
4
- export type CachedInstanceState = {
5
- current: unknown
6
- initial: unknown
7
- }
8
-
9
- type CachedInstance = {
10
- isRemovable: boolean
11
- element: PotokElement
12
- states: CachedInstanceState[]
13
- }
14
-
15
- export class RegisteredComponent {
16
- component: Component<any>
17
- subscribers: Set<HMRSubscriber>
18
- private cachedInstances: Map<string, CachedInstance>
19
-
20
- constructor(component: Component<any>) {
21
- this.component = component
22
- this.subscribers = new Set()
23
- this.cachedInstances = new Map()
24
- }
25
-
26
- getCachedInstance(instanceId: string): CachedInstance | undefined {
27
- return this.cachedInstances.get(instanceId)
28
- }
29
-
30
- addCachedInstance(
31
- instanceId: string,
32
- element: PotokElement,
33
- states: CachedInstanceState[],
34
- ) {
35
- this.cachedInstances.set(instanceId, {
36
- isRemovable: false,
37
- element,
38
- states,
39
- })
40
- }
41
-
42
- markInstanceAsRemovable(instanceId: string) {
43
- const cachedInstance = this.cachedInstances.get(instanceId)
44
- if (cachedInstance) {
45
- cachedInstance.isRemovable = true
46
- }
47
- }
48
-
49
- unmarkInstanceAsRemovable(instanceId: string) {
50
- const cachedInstance = this.cachedInstances.get(instanceId)
51
- if (cachedInstance) {
52
- cachedInstance.isRemovable = false
53
- }
54
- }
55
-
56
- removeCachedInstance(instanceId: string) {
57
- this.cachedInstances.delete(instanceId)
58
- }
59
- }
@@ -1,78 +0,0 @@
1
- import { Component } from '../types'
2
- import { ComponentId, HMRSubscriber, ModudeId } from './types'
3
- import { RegisteredComponent } from './registered-component'
4
-
5
- export class HMRRegistry {
6
- private components: Map<ModudeId, Map<ComponentId, RegisteredComponent>> =
7
- new Map()
8
-
9
- private getModuleComponentsMap(moduleId: ModudeId) {
10
- if (!this.components.has(moduleId)) {
11
- this.components.set(moduleId, new Map())
12
- }
13
-
14
- return this.components.get(moduleId)!
15
- }
16
-
17
- addComponent(
18
- moduleId: ModudeId,
19
- componentId: ComponentId,
20
- component: Component<any>,
21
- ): RegisteredComponent {
22
- const moduleComponentsMap = this.getModuleComponentsMap(moduleId)
23
-
24
- if (!moduleComponentsMap.has(componentId)) {
25
- moduleComponentsMap.set(componentId, new RegisteredComponent(component))
26
- }
27
-
28
- const registeredComponent = moduleComponentsMap.get(componentId)!
29
-
30
- registeredComponent.component = component
31
-
32
- return registeredComponent
33
- }
34
-
35
- getRegisteredComponent(
36
- moduleId: ModudeId,
37
- componentId: ComponentId,
38
- ): RegisteredComponent | undefined {
39
- return this.getModuleComponentsMap(moduleId).get(componentId)
40
- }
41
-
42
- subscribeToComponent(
43
- moduleId: ModudeId,
44
- componentId: ComponentId,
45
- subscriber: HMRSubscriber,
46
- ) {
47
- this.getRegisteredComponent(moduleId, componentId)?.subscribers.add(
48
- subscriber,
49
- )
50
-
51
- return () => {
52
- this.unsubscribeFromComponent(moduleId, componentId, subscriber)
53
- }
54
- }
55
-
56
- unsubscribeFromComponent(
57
- moduleId: ModudeId,
58
- componentId: ComponentId,
59
- subscriber: HMRSubscriber,
60
- ) {
61
- this.getRegisteredComponent(moduleId, componentId)?.subscribers.delete(
62
- subscriber,
63
- )
64
- }
65
-
66
- notifyComponentUpdate(moduleId: ModudeId, componentId: ComponentId) {
67
- const registeredComponent = this.getRegisteredComponent(
68
- moduleId,
69
- componentId,
70
- )
71
-
72
- if (!registeredComponent) return
73
-
74
- for (const subscriber of registeredComponent.subscribers) {
75
- subscriber(registeredComponent)
76
- }
77
- }
78
- }
package/src/hmr/types.ts DELETED
@@ -1,6 +0,0 @@
1
- import { RegisteredComponent } from './registered-component'
2
-
3
- export type HMRSubscriber = (component: RegisteredComponent | undefined) => void
4
-
5
- export type ModudeId = string
6
- export type ComponentId = string
package/src/hmr/utils.ts DELETED
@@ -1,20 +0,0 @@
1
- import { LibContext } from '../types'
2
-
3
- export function isWindowDefined(): boolean {
4
- return typeof window !== 'undefined'
5
- }
6
-
7
- export function getComponentInstanceId(context: LibContext): string {
8
- const indexes: number[] = []
9
-
10
- let currentContext: LibContext | null = context
11
-
12
- while (currentContext) {
13
- indexes.push(currentContext.index)
14
- currentContext = currentContext.parentBlock
15
- ? currentContext.parentBlock.context
16
- : null
17
- }
18
-
19
- return indexes.reverse().join('_')
20
- }