-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(qwik): don't bundle qwik internals in server
Since /server is a separate entry point, all qwik code should come from imports and not be copied into the library. Otherwise, we'd have multiple copies of singletons.
- Loading branch information
Showing
29 changed files
with
213 additions
and
215 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { assertTrue } from '../shared/error/assert'; | ||
|
||
export const mapApp_findIndx = <T>( | ||
elementVNode: (T | null)[], | ||
key: string, | ||
start: number | ||
): number => { | ||
assertTrue(start % 2 === 0, 'Expecting even number.'); | ||
let bottom = (start as number) >> 1; | ||
let top = (elementVNode.length - 2) >> 1; | ||
while (bottom <= top) { | ||
const mid = bottom + ((top - bottom) >> 1); | ||
const midKey = elementVNode[mid << 1] as string; | ||
if (midKey === key) { | ||
return mid << 1; | ||
} | ||
if (midKey < key) { | ||
bottom = mid + 1; | ||
} else { | ||
top = mid - 1; | ||
} | ||
} | ||
return (bottom << 1) ^ -1; | ||
}; | ||
|
||
export const mapArray_set = <T>( | ||
elementVNode: (T | null)[], | ||
key: string, | ||
value: T | null, | ||
start: number | ||
) => { | ||
const indx = mapApp_findIndx(elementVNode, key, start); | ||
if (indx >= 0) { | ||
if (value == null) { | ||
elementVNode.splice(indx, 2); | ||
} else { | ||
elementVNode[indx + 1] = value; | ||
} | ||
} else if (value != null) { | ||
elementVNode.splice(indx ^ -1, 0, key as any, value); | ||
} | ||
}; | ||
|
||
export const mapApp_remove = <T>( | ||
elementVNode: (T | null)[], | ||
key: string, | ||
start: number | ||
): T | null => { | ||
const indx = mapApp_findIndx(elementVNode, key, start); | ||
let value: T | null = null; | ||
if (indx >= 0) { | ||
value = elementVNode[indx + 1]; | ||
elementVNode.splice(indx, 2); | ||
return value; | ||
} | ||
return value; | ||
}; | ||
|
||
export const mapArray_get = <T>( | ||
elementVNode: (T | null)[], | ||
key: string, | ||
start: number | ||
): T | null => { | ||
const indx = mapApp_findIndx(elementVNode, key, start); | ||
if (indx >= 0) { | ||
return elementVNode[indx + 1] as T | null; | ||
} else { | ||
return 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
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
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,32 @@ | ||
/** QRL related utilities that you can import without importing all of Qwik. */ | ||
|
||
import { isDev } from '@qwik.dev/core/build'; | ||
import type { QRLInternal, SyncQRLInternal } from './qrl-class'; | ||
import type { QRL } from './qrl.public'; | ||
|
||
export const SYNC_QRL = '<sync>'; | ||
|
||
/** Sync QRL is a function which is serialized into `<script q:func="qwik/json">` tag. */ | ||
export const isSyncQrl = (value: any): value is SyncQRLInternal => { | ||
return isQrl(value) && value.$symbol$ == SYNC_QRL; | ||
}; | ||
|
||
export const isQrl = <T = unknown>(value: unknown): value is QRLInternal<T> => { | ||
return typeof value === 'function' && typeof (value as any).getSymbol === 'function'; | ||
}; | ||
|
||
export function assertQrl<T>(qrl: QRL<T>): asserts qrl is QRLInternal<T> { | ||
if (isDev) { | ||
if (!isQrl(qrl)) { | ||
throw new Error('Not a QRL'); | ||
} | ||
} | ||
} | ||
|
||
export const getSymbolHash = (symbolName: string) => { | ||
const index = symbolName.lastIndexOf('_'); | ||
if (index > -1) { | ||
return symbolName.slice(index + 1); | ||
} | ||
return symbolName; | ||
}; |
Oops, something went wrong.