valyrian.js 7.2.9 → 7.2.10
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.
- package/dist/dataset/index.d.ts +2 -2
- package/dist/dataset/index.d.ts.map +1 -1
- package/dist/dataset/index.js +11 -4
- package/dist/dataset/index.js.map +2 -2
- package/dist/dataset/index.mjs +10 -4
- package/dist/dataset/index.mjs.map +2 -2
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/index.js.map +2 -2
- package/dist/hooks/index.mjs.map +2 -2
- package/dist/index.d.ts +17 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +2 -2
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +3 -1
- package/dist/index.mjs.map +2 -2
- package/dist/node/index.js +7 -0
- package/dist/node/index.js.map +2 -2
- package/dist/node/index.mjs +6 -0
- package/dist/node/index.mjs.map +2 -2
- package/dist/node/utils/inline.d.ts +2 -2
- package/dist/node/utils/inline.d.ts.map +1 -1
- package/dist/node/utils/tree-adapter.d.ts +3 -3
- package/dist/node/utils/tree-adapter.d.ts.map +1 -1
- package/dist/proxy-signal/index.js +1 -0
- package/dist/proxy-signal/index.js.map +1 -1
- package/dist/request/index.js +1 -0
- package/dist/request/index.js.map +1 -1
- package/dist/router/index.d.ts +2 -2
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +5 -3
- package/dist/router/index.js.map +3 -3
- package/dist/router/index.mjs +4 -3
- package/dist/router/index.mjs.map +3 -3
- package/dist/signal/index.d.ts.map +1 -1
- package/dist/signal/index.js +3 -2
- package/dist/signal/index.js.map +2 -2
- package/dist/signal/index.mjs +2 -2
- package/dist/signal/index.mjs.map +2 -2
- package/dist/store/index.js +1 -0
- package/dist/store/index.js.map +1 -1
- package/dist/sw/index.d.ts +1 -1
- package/dist/sw/index.d.ts.map +1 -1
- package/dist/sw/index.js +1 -0
- package/dist/sw/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/lib/dataset/index.ts +15 -7
- package/lib/hooks/index.ts +2 -2
- package/lib/index.d.ts +0 -0
- package/lib/index.ts +22 -31
- package/lib/interfaces.ts.bak +141 -0
- package/lib/node/utils/inline.ts +17 -2
- package/lib/router/index.ts +16 -4
- package/lib/signal/index.ts +5 -5
- package/package.json +1 -1
- package/tsconfig.json +22 -8
- package/dist/interfaces.d.ts +0 -96
- package/dist/interfaces.d.ts.map +0 -1
- package/lib/interfaces.ts +0 -98
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../lib/router/index.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable no-use-before-define */\nimport {\n Component,\n POJOComponent,\n VnodeComponentInterface,\n VnodeWithDom,\n directive,\n isComponent,\n isNodeJs,\n isVnodeComponent,\n mount,\n setAttribute,\n v\n} from \"valyrian.js\";\n\ninterface Request {\n params: Record<string, any>;\n query: Record<string, any>;\n url: string;\n path: string;\n matches: string[];\n // eslint-disable-next-line no-unused-vars\n redirect: (path: string, parentComponent?: Component | POJOComponent | VnodeComponentInterface) => false;\n}\n\ninterface Middleware {\n // eslint-disable-next-line no-unused-vars\n (req: Request, res?: any):\n | Promise<any | Component | POJOComponent | VnodeComponentInterface>\n | any\n | Component\n | POJOComponent\n | VnodeComponentInterface;\n}\n\ninterface Middlewares extends Array<Middleware> {}\n\ninterface Path {\n method: string;\n path: string;\n middlewares: Middlewares;\n params: string[];\n regexp: RegExp;\n}\n\ninterface RouterInterface {\n paths: Path[];\n container: Element | string | null;\n query: Record<string, string | number>;\n options: Record<string, any>;\n url: string;\n path: string;\n params: Record<string, string | number | any>;\n matches: string[];\n pathPrefix: string;\n // eslint-disable-next-line no-unused-vars\n add(method: string, ...args: Middlewares): Router;\n // eslint-disable-next-line no-unused-vars\n use(...args: (string | Middleware | Router)[]): Router;\n\n routes(): string[];\n // eslint-disable-next-line no-unused-vars\n go(path: string, parentComponent?: Component | POJOComponent | VnodeComponentInterface): Promise<string | void>;\n}\n\ninterface RedirectFunction {\n // eslint-disable-next-line no-unused-vars\n (url: string, parentComponent?: Component, preventPushState?: boolean): string | void;\n}\n\nfunction flat(array: any) {\n return Array.isArray(array) ? array.flat(Infinity) : [array];\n}\n\nfunction getPathWithoutPrefix(path: string, prefix: string) {\n return getPathWithoutLastSlash(path.replace(new RegExp(`^${prefix}`), \"\"));\n}\n\nfunction getPathWithoutLastSlash(path: string) {\n let pathWithoutLastSlash = path.replace(/\\/$/, \"\");\n if (pathWithoutLastSlash === \"\") {\n pathWithoutLastSlash = \"/\";\n }\n return pathWithoutLastSlash;\n}\n\nconst addPath = ({\n router,\n method,\n path,\n middlewares\n}: {\n router: Router;\n method: string;\n path: string;\n middlewares: Middleware[];\n}): void => {\n if (!method || !path || !Array.isArray(middlewares) || middlewares.length === 0) {\n throw new Error(`Invalid route input: ${method} ${path} ${middlewares}`);\n }\n\n // Trim trailing slashes from the path\n let realpath = path.replace(/(\\S)(\\/+)$/, \"$1\");\n\n // Find the express-like params in the path\n let params = (realpath.match(/:(\\w+)?/gi) || [])\n // Set the names of the params found\n .map((param) => param.slice(1));\n\n // Generate a regular expression to match the path\n let regexpPath = \"^\" + realpath.replace(/:(\\w+)/gi, \"([^\\\\/\\\\s]+)\") + \"$\";\n\n router.paths.push({\n method,\n path: realpath,\n middlewares: flat(middlewares),\n params,\n regexp: new RegExp(regexpPath, \"i\")\n });\n};\n\n// Parse a query string into an object\nfunction parseQuery(queryParts?: string): Record<string, string> {\n // Split the query string into an array of name-value pairs\n let parts = queryParts ? queryParts.split(\"&\") : [];\n let query: Record<string, string> = {};\n\n // Iterate over the name-value pairs and add them to the query object\n for (let nameValue of parts) {\n let [name, value] = nameValue.split(\"=\", 2);\n query[name] = value || \"\";\n }\n\n return query;\n}\n\n// Search for middlewares that match a given path\nfunction searchMiddlewares(router: RouterInterface, path: string): Middlewares {\n let middlewares: Middlewares = [];\n let params: Record<string, any> = {};\n let matches = [];\n\n // Search for middlewares\n for (let item of router.paths) {\n let match = item.regexp.exec(path);\n\n // If we found middlewares\n if (Array.isArray(match)) {\n middlewares.push(...item.middlewares);\n match.shift();\n\n // Parse params\n for (let [index, key] of item.params.entries()) {\n params[key] = match[index];\n }\n\n // Add remaining matches to the array\n matches.push(...match);\n\n if (item.method === \"add\") {\n router.path = getPathWithoutPrefix(item.path, router.pathPrefix);\n break;\n }\n }\n }\n\n router.params = params;\n router.matches = matches;\n\n return middlewares;\n}\n\nasync function searchComponent(\n router: RouterInterface,\n middlewares: Middlewares\n): Promise<Component | VnodeComponentInterface | false | void> {\n // Define request object with default values\n const request: Request = {\n params: router.params,\n query: router.query,\n url: router.url,\n path: router.path,\n matches: router.matches,\n redirect: (path: string, parentComponent?: Component) => {\n router.go(path, parentComponent);\n // Return false to stop the middleware chain\n return false;\n }\n };\n\n // Initialize response variable\n let response;\n\n // Iterate through middlewares\n for (const middleware of middlewares) {\n // Invoke middleware and update response\n response = await middleware(request, response);\n\n // Return response if it's a valid component\n if (response !== undefined && (isComponent(response) || isVnodeComponent(response))) {\n return response;\n }\n\n // Return false if response is explicitly false to stop the middleware chain\n if (response === false) {\n return false;\n }\n }\n}\n\nexport class Router implements RouterInterface {\n paths: Path[] = [];\n container: Element | string | null = null;\n query: Record<string, string | number> = {};\n options: Record<string, any> = {};\n url: string = \"\";\n path: string = \"\";\n params: Record<string, string | number | any> = {};\n matches: string[] = [];\n pathPrefix: string = \"\";\n\n constructor(pathPrefix: string = \"\") {\n this.pathPrefix = pathPrefix;\n }\n\n add(path: string, ...middlewares: Middlewares): Router {\n let pathWithoutLastSlash = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);\n addPath({ router: this, method: \"add\", path: pathWithoutLastSlash, middlewares });\n return this;\n }\n\n use(...middlewares: Middlewares | Router[] | string[]): Router {\n let path = getPathWithoutLastSlash(\n `${this.pathPrefix}${typeof middlewares[0] === \"string\" ? middlewares.shift() : \"/\"}`\n );\n\n for (const item of middlewares) {\n if (item instanceof Router) {\n const subrouter = item as Router;\n for (const subpath of subrouter.paths) {\n addPath({\n router: this,\n method: subpath.method,\n path: `${path}${subpath.path}`.replace(/^\\/\\//, \"/\"),\n middlewares: subpath.middlewares\n });\n }\n continue;\n }\n\n if (typeof item === \"function\") {\n addPath({ router: this, method: \"use\", path: `${path}.*`, middlewares: [item as Middleware] });\n }\n }\n\n return this;\n }\n\n routes(): string[] {\n return this.paths.filter((path) => path.method === \"add\").map((path) => path.path);\n }\n\n async go(path: string, parentComponent?: Component, preventPushState = false): Promise<string | void> {\n if (!path) {\n throw new Error(\"router.url.required\");\n }\n\n let constructedPath = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);\n const parts = constructedPath.split(\"?\", 2);\n this.url = constructedPath;\n this.query = parseQuery(parts[1]);\n\n const middlewares = searchMiddlewares(this as RouterInterface, parts[0].replace(/(.+)\\/$/, \"$1\").split(\"#\")[0]);\n let component = await searchComponent(this as RouterInterface, middlewares);\n\n if (component === false) {\n return;\n }\n\n if (!component) {\n throw new Error(`The url ${constructedPath} requested wasn't found`);\n }\n\n if (isComponent(parentComponent) || isVnodeComponent(parentComponent)) {\n const childComponent = isVnodeComponent(component) ? component : v(component as Component, {});\n if (isVnodeComponent(parentComponent)) {\n parentComponent.children.push(childComponent);\n component = parentComponent;\n } else {\n component = v(parentComponent, {}, childComponent) as VnodeComponentInterface;\n }\n }\n\n if (!isNodeJs && !preventPushState) {\n window.history.pushState(null, \"\", constructedPath);\n }\n\n if (this.container) {\n return mount(this.container, component);\n }\n }\n\n getOnClickHandler(url: string) {\n return (e: MouseEvent) => {\n if (typeof url === \"string\" && url.length > 0) {\n this.go(url);\n }\n e.preventDefault();\n };\n }\n}\n\nlet localRedirect: RedirectFunction;\n\nexport function redirect(url: string, parentComponent?: Component, preventPushState = false): string | void {\n if (!localRedirect) {\n throw new Error(\"router.redirect.not.found\");\n }\n return localRedirect(url, parentComponent, preventPushState);\n}\n\nexport function mountRouter(elementContainer: string | any, router: Router): void {\n router.container = elementContainer;\n localRedirect = router.go.bind(router);\n\n if (!isNodeJs) {\n function onPopStateGoToRoute(): void {\n let pathWithoutPrefix = getPathWithoutPrefix(document.location.pathname, router.pathPrefix);\n (router as unknown as Router).go(pathWithoutPrefix, undefined, true);\n }\n window.addEventListener(\"popstate\", onPopStateGoToRoute, false);\n onPopStateGoToRoute();\n }\n\n directive(\"route\", (url: string, vnode: VnodeWithDom, oldnode?: VnodeWithDom): void => {\n setAttribute(\"href\", url, vnode, oldnode);\n setAttribute(\"onclick\", router.getOnClickHandler(url), vnode, oldnode);\n });\n}\n"],
|
|
5
|
-
"mappings": ";AACA;AAAA,EAKE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-use-before-define */\nimport {\n Component,\n POJOComponent,\n VnodeComponentInterface,\n VnodeWithDom,\n directive,\n isComponent,\n isNodeJs,\n isVnodeComponent,\n mount,\n setAttribute,\n v\n} from \"valyrian.js\";\n\ninterface Request {\n params: Record<string, any>;\n query: Record<string, any>;\n url: string;\n path: string;\n matches: string[];\n // eslint-disable-next-line no-unused-vars\n redirect: (path: string, parentComponent?: Component | POJOComponent | VnodeComponentInterface) => false;\n}\n\ninterface Middleware {\n // eslint-disable-next-line no-unused-vars\n (req: Request, res?: any):\n | Promise<any | Component | POJOComponent | VnodeComponentInterface>\n | any\n | Component\n | POJOComponent\n | VnodeComponentInterface;\n}\n\ninterface Middlewares extends Array<Middleware> {}\n\ninterface Path {\n method: string;\n path: string;\n middlewares: Middlewares;\n params: string[];\n regexp: RegExp;\n}\n\ninterface RouterInterface {\n paths: Path[];\n container: Element | string | null;\n query: Record<string, string | number>;\n options: Record<string, any>;\n url: string;\n path: string;\n params: Record<string, string | number | any>;\n matches: string[];\n pathPrefix: string;\n // eslint-disable-next-line no-unused-vars\n add(method: string, ...args: Middlewares): Router;\n // eslint-disable-next-line no-unused-vars\n use(...args: (string | Middleware | Router)[]): Router;\n\n routes(): string[];\n // eslint-disable-next-line no-unused-vars\n go(path: string, parentComponent?: Component | POJOComponent | VnodeComponentInterface): Promise<string | void>;\n}\n\ninterface RedirectFunction {\n // eslint-disable-next-line no-unused-vars\n (\n path: string,\n parentComponent?: Component | POJOComponent | VnodeComponentInterface,\n preventPushState?: boolean\n ): Promise<string | void>;\n}\n\nfunction flat(array: any) {\n return Array.isArray(array) ? array.flat(Infinity) : [array];\n}\n\nfunction getPathWithoutPrefix(path: string, prefix: string) {\n return getPathWithoutLastSlash(path.replace(new RegExp(`^${prefix}`), \"\"));\n}\n\nfunction getPathWithoutLastSlash(path: string) {\n let pathWithoutLastSlash = path.replace(/\\/$/, \"\");\n if (pathWithoutLastSlash === \"\") {\n pathWithoutLastSlash = \"/\";\n }\n return pathWithoutLastSlash;\n}\n\nconst addPath = ({\n router,\n method,\n path,\n middlewares\n}: {\n router: Router;\n method: string;\n path: string;\n middlewares: Middleware[];\n}): void => {\n if (!method || !path || !Array.isArray(middlewares) || middlewares.length === 0) {\n throw new Error(`Invalid route input: ${method} ${path} ${middlewares}`);\n }\n\n // Trim trailing slashes from the path\n let realpath = path.replace(/(\\S)(\\/+)$/, \"$1\");\n\n // Find the express-like params in the path\n let params = (realpath.match(/:(\\w+)?/gi) || [])\n // Set the names of the params found\n .map((param) => param.slice(1));\n\n // Generate a regular expression to match the path\n let regexpPath = \"^\" + realpath.replace(/:(\\w+)/gi, \"([^\\\\/\\\\s]+)\") + \"$\";\n\n router.paths.push({\n method,\n path: realpath,\n middlewares: flat(middlewares),\n params,\n regexp: new RegExp(regexpPath, \"i\")\n });\n};\n\n// Parse a query string into an object\nfunction parseQuery(queryParts?: string): Record<string, string> {\n // Split the query string into an array of name-value pairs\n let parts = queryParts ? queryParts.split(\"&\") : [];\n let query: Record<string, string> = {};\n\n // Iterate over the name-value pairs and add them to the query object\n for (let nameValue of parts) {\n let [name, value] = nameValue.split(\"=\", 2);\n query[name] = value || \"\";\n }\n\n return query;\n}\n\n// Search for middlewares that match a given path\nfunction searchMiddlewares(router: RouterInterface, path: string): Middlewares {\n let middlewares: Middlewares = [];\n let params: Record<string, any> = {};\n let matches = [];\n\n // Search for middlewares\n for (let item of router.paths) {\n let match = item.regexp.exec(path);\n\n // If we found middlewares\n if (Array.isArray(match)) {\n middlewares.push(...item.middlewares);\n match.shift();\n\n // Parse params\n for (let [index, key] of item.params.entries()) {\n params[key] = match[index];\n }\n\n // Add remaining matches to the array\n matches.push(...match);\n\n if (item.method === \"add\") {\n router.path = getPathWithoutPrefix(item.path, router.pathPrefix);\n break;\n }\n }\n }\n\n router.params = params;\n router.matches = matches;\n\n return middlewares;\n}\n\nasync function searchComponent(\n router: RouterInterface,\n middlewares: Middlewares\n): Promise<Component | VnodeComponentInterface | false | void> {\n // Define request object with default values\n const request: Request = {\n params: router.params,\n query: router.query,\n url: router.url,\n path: router.path,\n matches: router.matches,\n redirect: (path: string, parentComponent?: Component | POJOComponent | VnodeComponentInterface) => {\n router.go(path, parentComponent);\n // Return false to stop the middleware chain\n return false;\n }\n };\n\n // Initialize response variable\n let response;\n\n // Iterate through middlewares\n for (const middleware of middlewares) {\n // Invoke middleware and update response\n response = await middleware(request, response);\n\n // Return response if it's a valid component\n if (response !== undefined && (isComponent(response) || isVnodeComponent(response))) {\n return response;\n }\n\n // Return false if response is explicitly false to stop the middleware chain\n if (response === false) {\n return false;\n }\n }\n}\n\nexport class Router implements RouterInterface {\n paths: Path[] = [];\n container: Element | string | null = null;\n query: Record<string, string | number> = {};\n options: Record<string, any> = {};\n url: string = \"\";\n path: string = \"\";\n params: Record<string, string | number | any> = {};\n matches: string[] = [];\n pathPrefix: string = \"\";\n\n constructor(pathPrefix: string = \"\") {\n this.pathPrefix = pathPrefix;\n }\n\n add(path: string, ...middlewares: Middlewares): Router {\n let pathWithoutLastSlash = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);\n addPath({ router: this, method: \"add\", path: pathWithoutLastSlash, middlewares });\n return this;\n }\n\n use(...middlewares: Middlewares | Router[] | string[]): Router {\n let path = getPathWithoutLastSlash(\n `${this.pathPrefix}${typeof middlewares[0] === \"string\" ? middlewares.shift() : \"/\"}`\n );\n\n for (const item of middlewares) {\n if (item instanceof Router) {\n const subrouter = item as Router;\n for (const subpath of subrouter.paths) {\n addPath({\n router: this,\n method: subpath.method,\n path: `${path}${subpath.path}`.replace(/^\\/\\//, \"/\"),\n middlewares: subpath.middlewares\n });\n }\n continue;\n }\n\n if (typeof item === \"function\") {\n addPath({ router: this, method: \"use\", path: `${path}.*`, middlewares: [item as Middleware] });\n }\n }\n\n return this;\n }\n\n routes(): string[] {\n return this.paths.filter((path) => path.method === \"add\").map((path) => path.path);\n }\n\n async go(\n path: string,\n parentComponent?: Component | POJOComponent | VnodeComponentInterface,\n preventPushState = false\n ): Promise<string | void> {\n if (!path) {\n throw new Error(\"router.url.required\");\n }\n\n let constructedPath = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);\n const parts = constructedPath.split(\"?\", 2);\n this.url = constructedPath;\n this.query = parseQuery(parts[1]);\n\n const middlewares = searchMiddlewares(this as RouterInterface, parts[0].replace(/(.+)\\/$/, \"$1\").split(\"#\")[0]);\n let component = await searchComponent(this as RouterInterface, middlewares);\n\n if (component === false) {\n return;\n }\n\n if (!component) {\n throw new Error(`The url ${constructedPath} requested wasn't found`);\n }\n\n if (isComponent(parentComponent) || isVnodeComponent(parentComponent)) {\n const childComponent = isVnodeComponent(component) ? component : v(component as Component, {});\n if (isVnodeComponent(parentComponent)) {\n parentComponent.children.push(childComponent);\n component = parentComponent;\n } else {\n component = v(parentComponent, {}, childComponent) as VnodeComponentInterface;\n }\n }\n\n if (!isNodeJs && !preventPushState) {\n window.history.pushState(null, \"\", constructedPath);\n }\n\n if (this.container) {\n return mount(this.container, component);\n }\n }\n\n getOnClickHandler(url: string) {\n return (e: MouseEvent) => {\n if (typeof url === \"string\" && url.length > 0) {\n this.go(url);\n }\n e.preventDefault();\n };\n }\n}\n\nlet localRedirect: RedirectFunction;\n\nexport function redirect(\n url: string,\n parentComponent?: Component | POJOComponent | VnodeComponentInterface,\n preventPushState = false\n): Promise<string | void> {\n if (!localRedirect) {\n throw new Error(\"router.redirect.not.found\");\n }\n return localRedirect(url, parentComponent, preventPushState);\n}\n\nexport function mountRouter(elementContainer: string | any, router: Router): void {\n router.container = elementContainer;\n localRedirect = router.go.bind(router);\n\n if (!isNodeJs) {\n function onPopStateGoToRoute(): void {\n let pathWithoutPrefix = getPathWithoutPrefix(document.location.pathname, router.pathPrefix);\n (router as unknown as Router).go(pathWithoutPrefix, undefined, true);\n }\n window.addEventListener(\"popstate\", onPopStateGoToRoute, false);\n onPopStateGoToRoute();\n }\n\n directive(\"route\", (url: string, vnode: VnodeWithDom, oldnode?: VnodeWithDom): void => {\n setAttribute(\"href\", url, vnode, oldnode);\n setAttribute(\"onclick\", router.getOnClickHandler(url), vnode, oldnode);\n });\n}\n"],
|
|
5
|
+
"mappings": ";AACA;AAAA,EAKE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA6DP,SAAS,KAAK,OAAY;AACxB,SAAO,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK,QAAQ,IAAI,CAAC,KAAK;AAC7D;AAEA,SAAS,qBAAqB,MAAc,QAAgB;AAC1D,SAAO,wBAAwB,KAAK,QAAQ,IAAI,OAAO,IAAI,MAAM,EAAE,GAAG,EAAE,CAAC;AAC3E;AAEA,SAAS,wBAAwB,MAAc;AAC7C,MAAI,uBAAuB,KAAK,QAAQ,OAAO,EAAE;AACjD,MAAI,yBAAyB,IAAI;AAC/B,2BAAuB;AAAA,EACzB;AACA,SAAO;AACT;AAEA,IAAM,UAAU,CAAC;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAKY;AACV,MAAI,CAAC,UAAU,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a,WAAW,OAAO,kBAAkB,GAAG,GAAG,OAAO,OAAO;AAAA,EACvE,CAAC;AACH;",
|
|
6
|
+
"names": ["onPopStateGoToRoute"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/signal/index.ts"],"names":[],"mappings":"AAEA,UAAU,eAAe;IACvB,IAAI,GAAG,CAAC;CACT;AAED,UAAU,eAAe;IACvB,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC;CACpB;AAED,UAAU,kBAAkB;IAC1B,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;CAC5B;AAED,UAAU,sBAAuB,SAAQ,KAAK,CAAC,QAAQ,CAAC;CAAG;AAE3D,MAAM,WAAW,eAAgB,SAAQ,KAAK,CAAC,GAAG,CAAC;IACjD,CAAC,EAAE,eAAe,CAAC;IACnB,CAAC,EAAE,eAAe,CAAC;IACnB,CAAC,EAAE,kBAAkB,CAAC;IACtB,CAAC,EAAE,sBAAsB,CAAC;CAC3B;AAGD,wBAAgB,MAAM,CAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/signal/index.ts"],"names":[],"mappings":"AAEA,UAAU,eAAe;IACvB,IAAI,GAAG,CAAC;CACT;AAED,UAAU,eAAe;IACvB,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC;CACpB;AAED,UAAU,kBAAkB;IAC1B,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;CAC5B;AAED,UAAU,sBAAuB,SAAQ,KAAK,CAAC,QAAQ,CAAC;CAAG;AAE3D,MAAM,WAAW,eAAgB,SAAQ,KAAK,CAAC,GAAG,CAAC;IACjD,CAAC,EAAE,eAAe,CAAC;IACnB,CAAC,EAAE,eAAe,CAAC;IACnB,CAAC,EAAE,kBAAkB,CAAC;IACtB,CAAC,EAAE,sBAAsB,CAAC;CAC3B;AAGD,wBAAgB,MAAM,CAAC,YAAY,EAAE,GAAG,GAAG,eAAe,CAwIzD"}
|
package/dist/signal/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -25,7 +26,7 @@ module.exports = __toCommonJS(signal_exports);
|
|
|
25
26
|
var import_valyrian = require("valyrian.js");
|
|
26
27
|
function Signal(initialValue) {
|
|
27
28
|
const { vnode, component } = { ...import_valyrian.current };
|
|
28
|
-
if (vnode) {
|
|
29
|
+
if (vnode && component) {
|
|
29
30
|
if (!vnode.components) {
|
|
30
31
|
vnode.components = [];
|
|
31
32
|
}
|
|
@@ -87,7 +88,7 @@ function Signal(initialValue) {
|
|
|
87
88
|
}
|
|
88
89
|
};
|
|
89
90
|
let signal = [get, set, subscribe, subscriptions];
|
|
90
|
-
if (vnode) {
|
|
91
|
+
if (vnode && component) {
|
|
91
92
|
component.signals.push(signal);
|
|
92
93
|
}
|
|
93
94
|
return signal;
|
package/dist/signal/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../lib/signal/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { VnodeWithDom, current, onUnmount, updateVnode, v } from \"valyrian.js\";\n\ninterface GetterInterface {\n (): any;\n}\n\ninterface SetterInterface {\n (value: any): void;\n}\n\ninterface SubscribeInterface {\n (callback: Function): void;\n}\n\ninterface SubscriptionsInterface extends Array<Function> {}\n\nexport interface SignalInterface extends Array<any> {\n 0: GetterInterface;\n 1: SetterInterface;\n 2: SubscribeInterface;\n 3: SubscriptionsInterface;\n}\n\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport function Signal(initialValue): SignalInterface {\n // Create a copy of the current context object\n const { vnode, component } = { ...current };\n\n // Check if the context object has a vnode property\n if (vnode) {\n // Is first call\n if (!vnode.components) {\n // Set the components property to an empty array\n vnode.components = [];\n }\n\n // Check if the components array of the vnode object does not contain the component object\n if (vnode.components.indexOf(component) === -1) {\n // Set the calls property to -1\n vnode.signal_calls = -1;\n // Add the component to the components array\n vnode.components.push(component);\n\n // Check if the component object has a signals property\n if (!component.signals) {\n // Set the signals property of the component object to an empty array\n component.signals = [];\n // Add a function to the cleanup stack that removes the signals property from the component object\n onUnmount(() => Reflect.deleteProperty(component, \"signals\"));\n }\n }\n\n // Assign the signal variable to the signal stored at the index of the vnode object's calls property in the vnode's signals array\n let signal: SignalInterface = component.signals[++vnode.signal_calls];\n\n // If a signal has already been assigned to the signal variable, return it\n if (signal) {\n // Remove all subscriptions because we come from a new render\n signal[3].length = 0;\n\n // Return the signal\n return signal;\n }\n }\n\n // Declare a variable to store the current value of the Signal\n let value = initialValue;\n\n // Create an array to store functions that have subscribed to changes to the Signal's value\n const subscriptions: SubscriptionsInterface = [];\n\n // Define a function that allows other parts of the code to subscribe to changes to the Signal's value\n const subscribe = (callback) => {\n // Add the callback function to the subscriptions array if it is not already in the array\n if (subscriptions.indexOf(callback) === -1) {\n subscriptions.push(callback);\n }\n };\n\n // Set the vnodes to update when the Signal's value changes\n let vnodesToUpdate: Array<VnodeWithDom> = [];\n\n // This is the function that will be called when the Signal's value changes\n const updateVnodes = () => {\n // Create a copy of the vnodesToUpdate array and filter out any duplicate vnodes\n let vnodesToUpdateCopy = vnodesToUpdate.filter((vnode, index, self) => {\n return self.findIndex((v) => v.dom === vnode.dom) === index;\n });\n\n // Loop through the vnodesToUpdate array\n for (let i = 0, l = vnodesToUpdateCopy.length; i < l; i++) {\n const vnode2 = vnodesToUpdateCopy[i];\n // If it does, create a new vnode object based on the original vnode, its children, and its DOM and SVG properties\n let newVnode = v(vnode2.tag, vnode2.props, ...vnode2.initialChildren) as VnodeWithDom;\n newVnode.dom = vnode2.dom; // Set the new vnode object's DOM property to the old vnode object's DOM property\n newVnode.isSVG = vnode2.isSVG; // Set the new vnode object's isSVG property to the old vnode object's isSVG property\n\n // Update the vnode object\n updateVnode(newVnode, vnode2);\n }\n };\n\n // Define a function that returns the current value of the Signal\n function get() {\n // Get the current vnode from the context object\n const { vnode: vnode2 } = current;\n\n // If we have a current vnode, it means that a get function is being called from within a component\n // so we subscribe the vnode to be updated when the Signal's value changes\n if (vnode2 && vnodesToUpdate.indexOf(vnode2) === -1) {\n // We set the initialChildren to a copy of the vnode's children array\n // This is the case when the vnode is a component that has not been rendered yet and we need the initial children\n // because they could have the components that are using the Signal\n if (!vnode2.initialChildren) {\n vnode2.initialChildren = [...vnode2.children];\n }\n\n // Add the vnode to the vnodesToUpdate array\n vnodesToUpdate.push(vnode2);\n\n // Subscribe the updateVnodes function to the Signal\n subscribe(updateVnodes);\n }\n\n // Return the current value of the Signal\n return value;\n }\n\n // Define a function that allows the value of the Signal to be updated and notifies any subscribed functions of the change\n const set = (newValue) => {\n // If we have a current event on going, prevent the default action\n if (current.event) {\n current.event.preventDefault();\n }\n\n // Just return if the new value is the same as the current value\n if (newValue === value) {\n return;\n }\n\n // Update the value of the Signal\n value = newValue;\n\n // Call each subscribed function with the new value of the Signal as an argument\n for (let i = 0, l = subscriptions.length; i < l; i++) {\n subscriptions[i](value);\n }\n };\n\n // Assign the signal variable an array containing the get, set, and subscribe functions\n let signal: SignalInterface = [get, set, subscribe, subscriptions];\n\n // If the context object has a vnode property, add the signal to the vnode's signals array\n // and add the subscriptions array to the vnode's subscriptions array\n if (vnode) {\n component.signals.push(signal);\n }\n\n // Return the signal\n return signal;\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { VnodeWithDom, current, onUnmount, updateVnode, v } from \"valyrian.js\";\n\ninterface GetterInterface {\n (): any;\n}\n\ninterface SetterInterface {\n (value: any): void;\n}\n\ninterface SubscribeInterface {\n (callback: Function): void;\n}\n\ninterface SubscriptionsInterface extends Array<Function> {}\n\nexport interface SignalInterface extends Array<any> {\n 0: GetterInterface;\n 1: SetterInterface;\n 2: SubscribeInterface;\n 3: SubscriptionsInterface;\n}\n\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport function Signal(initialValue: any): SignalInterface {\n // Create a copy of the current context object\n const { vnode, component } = { ...current };\n\n // Check if the context object has a vnode property\n if (vnode && component) {\n // Is first call\n if (!vnode.components) {\n // Set the components property to an empty array\n vnode.components = [];\n }\n\n // Check if the components array of the vnode object does not contain the component object\n if (vnode.components.indexOf(component) === -1) {\n // Set the calls property to -1\n vnode.signal_calls = -1;\n // Add the component to the components array\n vnode.components.push(component);\n\n // Check if the component object has a signals property\n if (!component.signals) {\n // Set the signals property of the component object to an empty array\n component.signals = [];\n // Add a function to the cleanup stack that removes the signals property from the component object\n onUnmount(() => Reflect.deleteProperty(component, \"signals\"));\n }\n }\n\n // Assign the signal variable to the signal stored at the index of the vnode object's calls property in the vnode's signals array\n let signal: SignalInterface = component.signals[++vnode.signal_calls];\n\n // If a signal has already been assigned to the signal variable, return it\n if (signal) {\n // Remove all subscriptions because we come from a new render\n signal[3].length = 0;\n\n // Return the signal\n return signal;\n }\n }\n\n // Declare a variable to store the current value of the Signal\n let value = initialValue;\n\n // Create an array to store functions that have subscribed to changes to the Signal's value\n const subscriptions: SubscriptionsInterface = [];\n\n // Define a function that allows other parts of the code to subscribe to changes to the Signal's value\n const subscribe = (callback: Function) => {\n // Add the callback function to the subscriptions array if it is not already in the array\n if (subscriptions.indexOf(callback) === -1) {\n subscriptions.push(callback);\n }\n };\n\n // Set the vnodes to update when the Signal's value changes\n let vnodesToUpdate: Array<VnodeWithDom> = [];\n\n // This is the function that will be called when the Signal's value changes\n const updateVnodes = () => {\n // Create a copy of the vnodesToUpdate array and filter out any duplicate vnodes\n let vnodesToUpdateCopy = vnodesToUpdate.filter((vnode, index, self) => {\n return self.findIndex((v) => v.dom === vnode.dom) === index;\n });\n\n // Loop through the vnodesToUpdate array\n for (let i = 0, l = vnodesToUpdateCopy.length; i < l; i++) {\n const vnode2 = vnodesToUpdateCopy[i];\n // If it does, create a new vnode object based on the original vnode, its children, and its DOM and SVG properties\n let newVnode = v(vnode2.tag, vnode2.props, ...vnode2.initialChildren) as VnodeWithDom;\n newVnode.dom = vnode2.dom; // Set the new vnode object's DOM property to the old vnode object's DOM property\n newVnode.isSVG = vnode2.isSVG; // Set the new vnode object's isSVG property to the old vnode object's isSVG property\n\n // Update the vnode object\n updateVnode(newVnode, vnode2);\n }\n };\n\n // Define a function that returns the current value of the Signal\n function get() {\n // Get the current vnode from the context object\n const { vnode: vnode2 } = current;\n\n // If we have a current vnode, it means that a get function is being called from within a component\n // so we subscribe the vnode to be updated when the Signal's value changes\n if (vnode2 && vnodesToUpdate.indexOf(vnode2) === -1) {\n // We set the initialChildren to a copy of the vnode's children array\n // This is the case when the vnode is a component that has not been rendered yet and we need the initial children\n // because they could have the components that are using the Signal\n if (!vnode2.initialChildren) {\n vnode2.initialChildren = [...vnode2.children];\n }\n\n // Add the vnode to the vnodesToUpdate array\n vnodesToUpdate.push(vnode2);\n\n // Subscribe the updateVnodes function to the Signal\n subscribe(updateVnodes);\n }\n\n // Return the current value of the Signal\n return value;\n }\n\n // Define a function that allows the value of the Signal to be updated and notifies any subscribed functions of the change\n const set = (newValue: any) => {\n // If we have a current event on going, prevent the default action\n if (current.event) {\n current.event.preventDefault();\n }\n\n // Just return if the new value is the same as the current value\n if (newValue === value) {\n return;\n }\n\n // Update the value of the Signal\n value = newValue;\n\n // Call each subscribed function with the new value of the Signal as an argument\n for (let i = 0, l = subscriptions.length; i < l; i++) {\n subscriptions[i](value);\n }\n };\n\n // Assign the signal variable an array containing the get, set, and subscribe functions\n let signal: SignalInterface = [get, set, subscribe, subscriptions];\n\n // If the context object has a vnode property, add the signal to the vnode's signals array\n // and add the subscriptions array to the vnode's subscriptions array\n if (vnode && component) {\n component.signals.push(signal);\n }\n\n // Return the signal\n return signal;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;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AAA,EACF;AAGA,WAAS,MAAM;AAEb,UAAM,EAAE,OAAO,OAAO,IAAI;AAI1B,QAAI,UAAU,eAAe,QAAQ,MAAM,MAAM,IAAI;AAInD,UAAI,CAAC,OAAO,iBAAiB;AAC3B,eAAO,kBAAkB,CAAC,GAAG,OAAO,QAAQ;AAAA,MAC9C;AAGA,qBAAe,KAAK,MAAM;AAG1B,gBAAU,YAAY;AAAA,IACxB;AAGA,WAAO;AAAA,EACT;AAGA,QAAM,MAAM,CAAC,aAAkB;AAE7B,QAAI,wBAAQ,OAAO;AACjB,8BAAQ,MAAM,eAAe;AAAA,IAC/B;AAGA,QAAI,aAAa,OAAO;AACtB;AAAA,IACF;AAGA,YAAQ;AAGR,aAAS,IAAI,GAAG,IAAI,cAAc,QAAQ,IAAI,GAAG,KAAK;AACpD,oBAAc,CAAC,EAAE,KAAK;AAAA,IACxB;AAAA,EACF;AAGA,MAAI,SAA0B,CAAC,KAAK,KAAK,WAAW,aAAa;AAIjE,MAAI,SAAS,WAAW;AACtB,cAAU,QAAQ,KAAK,MAAM;AAAA,EAC/B;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": ["signal", "vnode", "v"]
|
|
7
7
|
}
|
package/dist/signal/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { current, onUnmount, updateVnode, v } from "valyrian.js";
|
|
3
3
|
function Signal(initialValue) {
|
|
4
4
|
const { vnode, component } = { ...current };
|
|
5
|
-
if (vnode) {
|
|
5
|
+
if (vnode && component) {
|
|
6
6
|
if (!vnode.components) {
|
|
7
7
|
vnode.components = [];
|
|
8
8
|
}
|
|
@@ -64,7 +64,7 @@ function Signal(initialValue) {
|
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
let signal = [get, set, subscribe, subscriptions];
|
|
67
|
-
if (vnode) {
|
|
67
|
+
if (vnode && component) {
|
|
68
68
|
component.signals.push(signal);
|
|
69
69
|
}
|
|
70
70
|
return signal;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../lib/signal/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { VnodeWithDom, current, onUnmount, updateVnode, v } from \"valyrian.js\";\n\ninterface GetterInterface {\n (): any;\n}\n\ninterface SetterInterface {\n (value: any): void;\n}\n\ninterface SubscribeInterface {\n (callback: Function): void;\n}\n\ninterface SubscriptionsInterface extends Array<Function> {}\n\nexport interface SignalInterface extends Array<any> {\n 0: GetterInterface;\n 1: SetterInterface;\n 2: SubscribeInterface;\n 3: SubscriptionsInterface;\n}\n\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport function Signal(initialValue): SignalInterface {\n // Create a copy of the current context object\n const { vnode, component } = { ...current };\n\n // Check if the context object has a vnode property\n if (vnode) {\n // Is first call\n if (!vnode.components) {\n // Set the components property to an empty array\n vnode.components = [];\n }\n\n // Check if the components array of the vnode object does not contain the component object\n if (vnode.components.indexOf(component) === -1) {\n // Set the calls property to -1\n vnode.signal_calls = -1;\n // Add the component to the components array\n vnode.components.push(component);\n\n // Check if the component object has a signals property\n if (!component.signals) {\n // Set the signals property of the component object to an empty array\n component.signals = [];\n // Add a function to the cleanup stack that removes the signals property from the component object\n onUnmount(() => Reflect.deleteProperty(component, \"signals\"));\n }\n }\n\n // Assign the signal variable to the signal stored at the index of the vnode object's calls property in the vnode's signals array\n let signal: SignalInterface = component.signals[++vnode.signal_calls];\n\n // If a signal has already been assigned to the signal variable, return it\n if (signal) {\n // Remove all subscriptions because we come from a new render\n signal[3].length = 0;\n\n // Return the signal\n return signal;\n }\n }\n\n // Declare a variable to store the current value of the Signal\n let value = initialValue;\n\n // Create an array to store functions that have subscribed to changes to the Signal's value\n const subscriptions: SubscriptionsInterface = [];\n\n // Define a function that allows other parts of the code to subscribe to changes to the Signal's value\n const subscribe = (callback) => {\n // Add the callback function to the subscriptions array if it is not already in the array\n if (subscriptions.indexOf(callback) === -1) {\n subscriptions.push(callback);\n }\n };\n\n // Set the vnodes to update when the Signal's value changes\n let vnodesToUpdate: Array<VnodeWithDom> = [];\n\n // This is the function that will be called when the Signal's value changes\n const updateVnodes = () => {\n // Create a copy of the vnodesToUpdate array and filter out any duplicate vnodes\n let vnodesToUpdateCopy = vnodesToUpdate.filter((vnode, index, self) => {\n return self.findIndex((v) => v.dom === vnode.dom) === index;\n });\n\n // Loop through the vnodesToUpdate array\n for (let i = 0, l = vnodesToUpdateCopy.length; i < l; i++) {\n const vnode2 = vnodesToUpdateCopy[i];\n // If it does, create a new vnode object based on the original vnode, its children, and its DOM and SVG properties\n let newVnode = v(vnode2.tag, vnode2.props, ...vnode2.initialChildren) as VnodeWithDom;\n newVnode.dom = vnode2.dom; // Set the new vnode object's DOM property to the old vnode object's DOM property\n newVnode.isSVG = vnode2.isSVG; // Set the new vnode object's isSVG property to the old vnode object's isSVG property\n\n // Update the vnode object\n updateVnode(newVnode, vnode2);\n }\n };\n\n // Define a function that returns the current value of the Signal\n function get() {\n // Get the current vnode from the context object\n const { vnode: vnode2 } = current;\n\n // If we have a current vnode, it means that a get function is being called from within a component\n // so we subscribe the vnode to be updated when the Signal's value changes\n if (vnode2 && vnodesToUpdate.indexOf(vnode2) === -1) {\n // We set the initialChildren to a copy of the vnode's children array\n // This is the case when the vnode is a component that has not been rendered yet and we need the initial children\n // because they could have the components that are using the Signal\n if (!vnode2.initialChildren) {\n vnode2.initialChildren = [...vnode2.children];\n }\n\n // Add the vnode to the vnodesToUpdate array\n vnodesToUpdate.push(vnode2);\n\n // Subscribe the updateVnodes function to the Signal\n subscribe(updateVnodes);\n }\n\n // Return the current value of the Signal\n return value;\n }\n\n // Define a function that allows the value of the Signal to be updated and notifies any subscribed functions of the change\n const set = (newValue) => {\n // If we have a current event on going, prevent the default action\n if (current.event) {\n current.event.preventDefault();\n }\n\n // Just return if the new value is the same as the current value\n if (newValue === value) {\n return;\n }\n\n // Update the value of the Signal\n value = newValue;\n\n // Call each subscribed function with the new value of the Signal as an argument\n for (let i = 0, l = subscriptions.length; i < l; i++) {\n subscriptions[i](value);\n }\n };\n\n // Assign the signal variable an array containing the get, set, and subscribe functions\n let signal: SignalInterface = [get, set, subscribe, subscriptions];\n\n // If the context object has a vnode property, add the signal to the vnode's signals array\n // and add the subscriptions array to the vnode's subscriptions array\n if (vnode) {\n component.signals.push(signal);\n }\n\n // Return the signal\n return signal;\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAuB,SAAS,WAAW,aAAa,SAAS;AAwB1D,SAAS,OAAO,
|
|
4
|
+
"sourcesContent": ["import { VnodeWithDom, current, onUnmount, updateVnode, v } from \"valyrian.js\";\n\ninterface GetterInterface {\n (): any;\n}\n\ninterface SetterInterface {\n (value: any): void;\n}\n\ninterface SubscribeInterface {\n (callback: Function): void;\n}\n\ninterface SubscriptionsInterface extends Array<Function> {}\n\nexport interface SignalInterface extends Array<any> {\n 0: GetterInterface;\n 1: SetterInterface;\n 2: SubscribeInterface;\n 3: SubscriptionsInterface;\n}\n\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport function Signal(initialValue: any): SignalInterface {\n // Create a copy of the current context object\n const { vnode, component } = { ...current };\n\n // Check if the context object has a vnode property\n if (vnode && component) {\n // Is first call\n if (!vnode.components) {\n // Set the components property to an empty array\n vnode.components = [];\n }\n\n // Check if the components array of the vnode object does not contain the component object\n if (vnode.components.indexOf(component) === -1) {\n // Set the calls property to -1\n vnode.signal_calls = -1;\n // Add the component to the components array\n vnode.components.push(component);\n\n // Check if the component object has a signals property\n if (!component.signals) {\n // Set the signals property of the component object to an empty array\n component.signals = [];\n // Add a function to the cleanup stack that removes the signals property from the component object\n onUnmount(() => Reflect.deleteProperty(component, \"signals\"));\n }\n }\n\n // Assign the signal variable to the signal stored at the index of the vnode object's calls property in the vnode's signals array\n let signal: SignalInterface = component.signals[++vnode.signal_calls];\n\n // If a signal has already been assigned to the signal variable, return it\n if (signal) {\n // Remove all subscriptions because we come from a new render\n signal[3].length = 0;\n\n // Return the signal\n return signal;\n }\n }\n\n // Declare a variable to store the current value of the Signal\n let value = initialValue;\n\n // Create an array to store functions that have subscribed to changes to the Signal's value\n const subscriptions: SubscriptionsInterface = [];\n\n // Define a function that allows other parts of the code to subscribe to changes to the Signal's value\n const subscribe = (callback: Function) => {\n // Add the callback function to the subscriptions array if it is not already in the array\n if (subscriptions.indexOf(callback) === -1) {\n subscriptions.push(callback);\n }\n };\n\n // Set the vnodes to update when the Signal's value changes\n let vnodesToUpdate: Array<VnodeWithDom> = [];\n\n // This is the function that will be called when the Signal's value changes\n const updateVnodes = () => {\n // Create a copy of the vnodesToUpdate array and filter out any duplicate vnodes\n let vnodesToUpdateCopy = vnodesToUpdate.filter((vnode, index, self) => {\n return self.findIndex((v) => v.dom === vnode.dom) === index;\n });\n\n // Loop through the vnodesToUpdate array\n for (let i = 0, l = vnodesToUpdateCopy.length; i < l; i++) {\n const vnode2 = vnodesToUpdateCopy[i];\n // If it does, create a new vnode object based on the original vnode, its children, and its DOM and SVG properties\n let newVnode = v(vnode2.tag, vnode2.props, ...vnode2.initialChildren) as VnodeWithDom;\n newVnode.dom = vnode2.dom; // Set the new vnode object's DOM property to the old vnode object's DOM property\n newVnode.isSVG = vnode2.isSVG; // Set the new vnode object's isSVG property to the old vnode object's isSVG property\n\n // Update the vnode object\n updateVnode(newVnode, vnode2);\n }\n };\n\n // Define a function that returns the current value of the Signal\n function get() {\n // Get the current vnode from the context object\n const { vnode: vnode2 } = current;\n\n // If we have a current vnode, it means that a get function is being called from within a component\n // so we subscribe the vnode to be updated when the Signal's value changes\n if (vnode2 && vnodesToUpdate.indexOf(vnode2) === -1) {\n // We set the initialChildren to a copy of the vnode's children array\n // This is the case when the vnode is a component that has not been rendered yet and we need the initial children\n // because they could have the components that are using the Signal\n if (!vnode2.initialChildren) {\n vnode2.initialChildren = [...vnode2.children];\n }\n\n // Add the vnode to the vnodesToUpdate array\n vnodesToUpdate.push(vnode2);\n\n // Subscribe the updateVnodes function to the Signal\n subscribe(updateVnodes);\n }\n\n // Return the current value of the Signal\n return value;\n }\n\n // Define a function that allows the value of the Signal to be updated and notifies any subscribed functions of the change\n const set = (newValue: any) => {\n // If we have a current event on going, prevent the default action\n if (current.event) {\n current.event.preventDefault();\n }\n\n // Just return if the new value is the same as the current value\n if (newValue === value) {\n return;\n }\n\n // Update the value of the Signal\n value = newValue;\n\n // Call each subscribed function with the new value of the Signal as an argument\n for (let i = 0, l = subscriptions.length; i < l; i++) {\n subscriptions[i](value);\n }\n };\n\n // Assign the signal variable an array containing the get, set, and subscribe functions\n let signal: SignalInterface = [get, set, subscribe, subscriptions];\n\n // If the context object has a vnode property, add the signal to the vnode's signals array\n // and add the subscriptions array to the vnode's subscriptions array\n if (vnode && component) {\n component.signals.push(signal);\n }\n\n // Return the signal\n return signal;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAuB,SAAS,WAAW,aAAa,SAAS;AAwB1D,SAAS,OAAO,cAAoC;AAEzD,QAAM,EAAE,OAAO,UAAU,IAAI,EAAE,GAAG,QAAQ;AAG1C,MAAI,SAAS,WAAW;AAEtB,QAAI,CAAC,MAAM,YAAY;AAErB,YAAM,aAAa,CAAC;AAAA,IACtB;AAGA,QAAI,MAAM,WAAW,QAAQ,SAAS,MAAM,IAAI;AAE9C,YAAM,eAAe;AAErB,YAAM,WAAW,KAAK,SAAS;AAG/B,UAAI,CAAC,UAAU,SAAS;AAEtB,kBAAU,UAAU,CAAC;AAErB,kBAAU,MAAM,QAAQ,eAAe,WAAW,SAAS,CAAC;AAAA,MAC9D;AAAA,IACF;AAGA,QAAIA,UAA0B,UAAU,QAAQ,EAAE,MAAM,YAAY;AAGpE,QAAIA,SAAQ;AAEV,MAAAA,QAAO,CAAC,EAAE,SAAS;AAGnB,aAAOA;AAAA,IACT;AAAA,EACF;AAGA,MAAI,QAAQ;AAGZ,QAAM,gBAAwC,CAAC;AAG/C,QAAM,YAAY,CAAC,aAAuB;AAExC,QAAI,cAAc,QAAQ,QAAQ,MAAM,IAAI;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7
7
|
}
|
package/dist/store/index.js
CHANGED
package/dist/store/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../lib/store/index.ts"],
|
|
4
4
|
"sourcesContent": ["import { update } from \"valyrian.js\";\n\ninterface StoreOptions {\n state?: Record<string, unknown> | (() => Record<string, unknown>);\n getters?: Record<string, Function>;\n mutations?: Record<string, Function>;\n actions?: Record<string, Function>;\n}\n\ninterface StoreInstance {\n // eslint-disable-next-line no-unused-vars\n new (options: StoreOptions): StoreInstance;\n state: Record<string, any>;\n getters?: Record<string, any>;\n // eslint-disable-next-line no-unused-vars\n commit: (type: string, ...payload: any[]) => void;\n // eslint-disable-next-line no-unused-vars\n dispatch: (type: string, ...payload: any[]) => void;\n}\n\nfunction keyExists(typeOfKey: string, object: Record<string, unknown>, key: string) {\n if (key in object === false) {\n throw new Error(`The ${typeOfKey} \"${key}\" does not exists.`);\n }\n}\n\nfunction deepFreeze(obj: any) {\n if (typeof obj === \"object\" && obj !== null && !Object.isFrozen(obj)) {\n if (Array.isArray(obj)) {\n for (let i = 0, l = obj.length; i < l; i++) {\n deepFreeze(obj[i]);\n }\n } else {\n let props = Reflect.ownKeys(obj);\n for (let i = 0, l = props.length; i < l; i++) {\n deepFreeze(obj[props[i]]);\n }\n }\n Object.freeze(obj);\n }\n\n return obj;\n}\n\nlet updateTimeout: any;\nfunction delayedUpdate() {\n clearTimeout(updateTimeout);\n updateTimeout = setTimeout(update);\n}\n\nexport const Store = function Store(\n this: StoreInstance,\n { state = {}, getters = {}, actions = {}, mutations = {} }: StoreOptions = {}\n) {\n let frozen = true;\n\n function isUnfrozen() {\n if (frozen) {\n throw new Error(\"You need to commit a mutation to change the state\");\n }\n }\n\n let localState = typeof state === \"function\" ? state() : state;\n\n this.state = new Proxy(localState || {}, {\n get: (state, prop: string) => deepFreeze(state[prop]),\n set: (state, prop: string, value: any) => {\n isUnfrozen();\n state[prop] = value;\n return true;\n },\n deleteProperty: (state, prop: string) => {\n isUnfrozen();\n Reflect.deleteProperty(state, prop);\n return true;\n }\n });\n\n this.getters = new Proxy(getters, {\n get: (getters, getter: string) => {\n try {\n return getters[getter](this.state, this.getters);\n } catch (e) {\n // Getters should fail silently\n }\n }\n });\n\n this.commit = (mutation, ...args) => {\n keyExists(\"mutation\", mutations, mutation);\n frozen = false;\n mutations[mutation](this.state, ...args);\n frozen = true;\n delayedUpdate();\n };\n\n this.dispatch = (action, ...args) => {\n keyExists(\"action\", actions, action);\n return Promise.resolve(actions[action](this, ...args));\n };\n} as unknown as StoreInstance;\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAuB;AAoBvB,SAAS,UAAU,WAAmB,QAAiC,KAAa;AAClF,MAAI,OAAO,WAAW,OAAO;AAC3B,UAAM,IAAI,MAAM,OAAO,SAAS,KAAK,GAAG,oBAAoB;AAAA,EAC9D;AACF;AAEA,SAAS,WAAW,KAAU;AAC5B,MAAI,OAAO,QAAQ,YAAY,QAAQ,QAAQ,CAAC,OAAO,SAAS,GAAG,GAAG;AACpE,QAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,eAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,IAAI,GAAG,KAAK;AAC1C,mBAAW,IAAI,CAAC,CAAC;AAAA,MACnB;AAAA,IACF,OAAO;AACL,UAAI,QAAQ,QAAQ,QAAQ,GAAG;AAC/B,eAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,IAAI,GAAG,KAAK;AAC5C,mBAAW,IAAI,MAAM,CAAC,CAAC,CAAC;AAAA,MAC1B;AAAA,IACF;AACA,WAAO,OAAO,GAAG;AAAA,EACnB;AAEA,SAAO;AACT;AAEA,IAAI;AACJ,SAAS,gBAAgB;AACvB,eAAa,aAAa;AAC1B,kBAAgB,WAAW,sBAAM;AACnC;AAEO,IAAM,QAAQ,SAASA,OAE5B,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export declare function registerSw(file?: string, options?: RegistrationOptions): Promise<ServiceWorkerContainer>;
|
|
1
|
+
export declare function registerSw(file?: string, options?: RegistrationOptions): Promise<ServiceWorkerContainer | undefined>;
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/sw/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/sw/index.ts"],"names":[],"mappings":"AAEA,wBAAsB,UAAU,CAAC,IAAI,SAAY,EAAE,OAAO,GAAE,mBAAoC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/sw/index.ts"],"names":[],"mappings":"AAEA,wBAAsB,UAAU,CAAC,IAAI,SAAY,EAAE,OAAO,GAAE,mBAAoC,+CAM/F"}
|
package/dist/sw/index.js
CHANGED
package/dist/sw/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../lib/sw/index.ts"],
|
|
4
4
|
"sourcesContent": ["import { isNodeJs } from \"valyrian.js\";\n\nexport async function registerSw(file = \"./sw.js\", options: RegistrationOptions = { scope: \"/\" }) {\n if (isNodeJs) {\n return;\n }\n await navigator.serviceWorker.register(file, options);\n return navigator.serviceWorker;\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAyB;AAEzB,eAAsB,WAAW,OAAO,WAAW,UAA+B,EAAE,OAAO,IAAI,GAAG;AAChG,MAAI,0BAAU;AACZ;AAAA,EACF;AACA,QAAM,UAAU,cAAc,SAAS,MAAM,OAAO;AACpD,SAAO,UAAU;AACnB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"5.2.2"}
|
package/lib/dataset/index.ts
CHANGED
|
@@ -35,9 +35,9 @@ function deepFreeze(obj: any) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export class DataSet<T> implements DataSetInterface<T> {
|
|
38
|
-
#vnode: VnodeWithDom;
|
|
38
|
+
#vnode: VnodeWithDom | null = null;
|
|
39
39
|
// eslint-disable-next-line no-unused-vars
|
|
40
|
-
#handler: DataSetHandler<T
|
|
40
|
+
#handler: DataSetHandler<T> | null = null;
|
|
41
41
|
#data: T[] = [];
|
|
42
42
|
#isFrozen = false;
|
|
43
43
|
#dataProxy: T[] | null = null;
|
|
@@ -64,7 +64,7 @@ export class DataSet<T> implements DataSetInterface<T> {
|
|
|
64
64
|
set: () => {
|
|
65
65
|
throw new Error("You need to use the add, update or delete methods to change the data");
|
|
66
66
|
},
|
|
67
|
-
get(target, prop) {
|
|
67
|
+
get(target: any, prop: string) {
|
|
68
68
|
return target[prop];
|
|
69
69
|
},
|
|
70
70
|
deleteProperty: () => {
|
|
@@ -86,6 +86,10 @@ export class DataSet<T> implements DataSetInterface<T> {
|
|
|
86
86
|
|
|
87
87
|
reset(data: T[]) {
|
|
88
88
|
this.#setData(data);
|
|
89
|
+
if (this.#vnode === null || this.#handler === null) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
89
93
|
let vnode = this.#vnode;
|
|
90
94
|
let handler = this.#handler;
|
|
91
95
|
|
|
@@ -132,6 +136,10 @@ export class DataSet<T> implements DataSetInterface<T> {
|
|
|
132
136
|
this.#data.push(...data);
|
|
133
137
|
}
|
|
134
138
|
|
|
139
|
+
if (this.#vnode === null || this.#handler === null) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
135
143
|
let vnode = this.#vnode;
|
|
136
144
|
let handler = this.#handler;
|
|
137
145
|
|
|
@@ -147,8 +155,8 @@ export class DataSet<T> implements DataSetInterface<T> {
|
|
|
147
155
|
}
|
|
148
156
|
}
|
|
149
157
|
|
|
150
|
-
delete(index) {
|
|
151
|
-
if (this.#data) {
|
|
158
|
+
delete(index: number) {
|
|
159
|
+
if (this.#data && this.#vnode) {
|
|
152
160
|
let child = this.#vnode.children[index];
|
|
153
161
|
if (this.#isFrozen) {
|
|
154
162
|
this.#setData(this.data.filter((_, i) => i !== index));
|
|
@@ -161,8 +169,8 @@ export class DataSet<T> implements DataSetInterface<T> {
|
|
|
161
169
|
}
|
|
162
170
|
}
|
|
163
171
|
|
|
164
|
-
update(index, item: Partial<T>) {
|
|
165
|
-
if (this.#data) {
|
|
172
|
+
update(index: number, item: Partial<T>) {
|
|
173
|
+
if (this.#data && this.#vnode && this.#handler) {
|
|
166
174
|
let child = this.#vnode.children[index];
|
|
167
175
|
if (this.#isFrozen) {
|
|
168
176
|
this.#setData(this.#data.map((d, i) => (i === index ? { ...d, ...item } : d)));
|
package/lib/hooks/index.ts
CHANGED
|
@@ -36,7 +36,7 @@ export const createHook = function createHook({
|
|
|
36
36
|
return (...args: any[]) => {
|
|
37
37
|
let { component, vnode } = current as CurrentOnPatch;
|
|
38
38
|
|
|
39
|
-
let hook = null;
|
|
39
|
+
let hook: any = null;
|
|
40
40
|
|
|
41
41
|
if (vnode) {
|
|
42
42
|
// Init the components array for the current vnode
|
|
@@ -109,7 +109,7 @@ export const useState = createHook({
|
|
|
109
109
|
get.toJSON = get.valueOf = get;
|
|
110
110
|
get.toString = () => `${value}`;
|
|
111
111
|
|
|
112
|
-
function set(newValue) {
|
|
112
|
+
function set(newValue: any) {
|
|
113
113
|
// Prevent default event if it exists
|
|
114
114
|
if (current.event) {
|
|
115
115
|
current.event.preventDefault();
|
package/lib/index.d.ts
ADDED
|
File without changes
|
package/lib/index.ts
CHANGED
|
@@ -3,26 +3,24 @@
|
|
|
3
3
|
/* eslint-disable sonarjs/cognitive-complexity */
|
|
4
4
|
/* eslint-disable complexity */
|
|
5
5
|
|
|
6
|
+
interface DefaultRecord extends Record<string | number | symbol, any> {}
|
|
7
|
+
|
|
6
8
|
// The VnodeProperties interface represents properties that can be passed to a virtual node.
|
|
7
|
-
export interface VnodeProperties {
|
|
9
|
+
export interface VnodeProperties extends DefaultRecord {
|
|
8
10
|
// A unique key for the virtual node, which can be a string or a number.
|
|
9
11
|
// This is useful for optimizing updates in a list of nodes.
|
|
10
12
|
key?: string | number;
|
|
11
13
|
// A state object that is associated with the virtual node.
|
|
12
14
|
state?: any;
|
|
13
|
-
// An index signature that allows for any other properties to be added.
|
|
14
|
-
[key: string | number | symbol]: any;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
// The DomElement interface extends the Element interface with an index signature.
|
|
18
18
|
// This allows for any additional properties to be added to DOM elements.
|
|
19
|
-
export interface DomElement extends Element {
|
|
20
|
-
[key: string]: any;
|
|
21
|
-
}
|
|
19
|
+
export interface DomElement extends Element, DefaultRecord {}
|
|
22
20
|
|
|
23
21
|
// The VnodeInterface represents a virtual node. It has a number of optional fields,
|
|
24
22
|
// including a tag, props, children, and a DOM element.
|
|
25
|
-
export interface VnodeInterface {
|
|
23
|
+
export interface VnodeInterface extends DefaultRecord {
|
|
26
24
|
// The constructor for the virtual node. It takes a tag, props, and children as arguments.
|
|
27
25
|
// The tag can be a string, a component, or a POJO component.
|
|
28
26
|
// eslint-disable-next-line no-unused-vars
|
|
@@ -39,8 +37,6 @@ export interface VnodeInterface {
|
|
|
39
37
|
dom?: DomElement;
|
|
40
38
|
// A boolean indicating whether the virtual node has been processed in the keyed diffing algorithm.
|
|
41
39
|
processed?: boolean;
|
|
42
|
-
// An index signature that allows for any additional properties to be added to the virtual node.
|
|
43
|
-
[key: string | number | symbol]: any;
|
|
44
40
|
}
|
|
45
41
|
|
|
46
42
|
// The VnodeWithDom interface represents a virtual node that has a DOM element associated with it.
|
|
@@ -50,28 +46,24 @@ export interface VnodeWithDom extends VnodeInterface {
|
|
|
50
46
|
|
|
51
47
|
// The Component interface represents a function that returns a virtual node or a list of virtual nodes.
|
|
52
48
|
// It can also have additional properties.
|
|
53
|
-
export interface Component {
|
|
49
|
+
export interface Component extends DefaultRecord {
|
|
54
50
|
// The function that returns a virtual node or a list of virtual nodes.
|
|
55
51
|
// It can take props and children as arguments.
|
|
56
52
|
// eslint-disable-next-line no-unused-vars
|
|
57
53
|
(props?: VnodeProperties | null, ...children: any[]): VnodeInterface | Children | any;
|
|
58
|
-
// An index signature that allows for any additional properties to be added to the component.
|
|
59
|
-
[key: string]: any;
|
|
60
54
|
}
|
|
61
55
|
|
|
62
56
|
// The POJOComponent interface represents a "plain old JavaScript object" (POJO) component.
|
|
63
57
|
// It has a view function that returns a virtual node or a list of virtual nodes,
|
|
64
58
|
// as well as optional props and children.
|
|
65
59
|
// It can be used also to identify class instance components.
|
|
66
|
-
export interface POJOComponent {
|
|
60
|
+
export interface POJOComponent extends DefaultRecord {
|
|
67
61
|
// The view function that returns a virtual node or a list of virtual nodes.
|
|
68
62
|
view: Component;
|
|
69
63
|
// The props for the component.
|
|
70
64
|
props?: VnodeProperties | null;
|
|
71
65
|
// The children for the component.
|
|
72
66
|
children?: any[];
|
|
73
|
-
// An index signature that allows for any additional properties to be added to the POJO component.
|
|
74
|
-
[key: string]: any;
|
|
75
67
|
}
|
|
76
68
|
|
|
77
69
|
// The VnodeComponentInterface represents a virtual node that has a component as its tag.
|
|
@@ -95,15 +87,11 @@ export interface Directive {
|
|
|
95
87
|
}
|
|
96
88
|
|
|
97
89
|
// The Directives interface is a mapping of directive names to Directive functions.
|
|
98
|
-
export interface Directives {
|
|
99
|
-
[key: string]: Directive;
|
|
100
|
-
}
|
|
90
|
+
export interface Directives extends Record<string, Directive> {}
|
|
101
91
|
|
|
102
92
|
// The ReservedProps interface is a mapping of reserved prop names to the value `true`.
|
|
103
93
|
// These prop names cannot be used as custom prop names.
|
|
104
|
-
export interface ReservedProps {
|
|
105
|
-
[key: string]: true;
|
|
106
|
-
}
|
|
94
|
+
export interface ReservedProps extends Record<string, true> {}
|
|
107
95
|
|
|
108
96
|
// The Current interface represents the current component and virtual node that are being processed.
|
|
109
97
|
export interface Current {
|
|
@@ -127,6 +115,7 @@ export interface V {
|
|
|
127
115
|
// eslint-disable-next-line no-unused-vars, no-use-before-define
|
|
128
116
|
fragment(_: any, ...children: Children): Children;
|
|
129
117
|
}
|
|
118
|
+
|
|
130
119
|
// 'textTag' is a constant string that is used to represent text nodes in the virtual DOM.
|
|
131
120
|
const textTag = "#text";
|
|
132
121
|
|
|
@@ -153,8 +142,10 @@ export const Vnode = function Vnode(this: VnodeInterface, tag: string, props: Vn
|
|
|
153
142
|
|
|
154
143
|
// 'isComponent' is a function that returns true if the given 'component' is a valid component and false otherwise.
|
|
155
144
|
// A component is either a function or an object with a 'view' function.
|
|
156
|
-
export function isComponent(component): component is Component {
|
|
157
|
-
return
|
|
145
|
+
export function isComponent(component: unknown): component is Component {
|
|
146
|
+
return Boolean(
|
|
147
|
+
component && (typeof component === "function" || (typeof component === "object" && "view" in component))
|
|
148
|
+
);
|
|
158
149
|
}
|
|
159
150
|
|
|
160
151
|
// 'isVnode' is a function that returns true if the given 'object' is a 'Vnode' instance and false otherwise.
|
|
@@ -268,28 +259,28 @@ const onUpdateSet: Set<Function> = new Set();
|
|
|
268
259
|
const onUnmountSet: Set<Function> = new Set();
|
|
269
260
|
|
|
270
261
|
// These functions allow users to register callbacks for the corresponding lifecycle events.
|
|
271
|
-
export function onMount(callback) {
|
|
262
|
+
export function onMount(callback: Function) {
|
|
272
263
|
if (!isMounted) {
|
|
273
264
|
onMountSet.add(callback);
|
|
274
265
|
}
|
|
275
266
|
}
|
|
276
267
|
|
|
277
|
-
export function onUpdate(callback) {
|
|
268
|
+
export function onUpdate(callback: Function) {
|
|
278
269
|
onUpdateSet.add(callback);
|
|
279
270
|
}
|
|
280
271
|
|
|
281
|
-
export function onCleanup(callback) {
|
|
272
|
+
export function onCleanup(callback: Function) {
|
|
282
273
|
onCleanupSet.add(callback);
|
|
283
274
|
}
|
|
284
275
|
|
|
285
|
-
export function onUnmount(callback) {
|
|
276
|
+
export function onUnmount(callback: Function) {
|
|
286
277
|
if (!isMounted) {
|
|
287
278
|
onUnmountSet.add(callback);
|
|
288
279
|
}
|
|
289
280
|
}
|
|
290
281
|
|
|
291
282
|
// This function is used to call all the callbacks in a given set.
|
|
292
|
-
function callSet(set) {
|
|
283
|
+
function callSet(set: Set<Function>) {
|
|
293
284
|
for (let callback of set) {
|
|
294
285
|
callback();
|
|
295
286
|
}
|
|
@@ -684,13 +675,13 @@ export function patch(newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void {
|
|
|
684
675
|
let newTreeLength = newTree.length;
|
|
685
676
|
|
|
686
677
|
// Create an object that maps keys to indices in the old tree
|
|
687
|
-
let oldKeyedList:
|
|
678
|
+
let oldKeyedList: Record<string, number> = {};
|
|
688
679
|
for (let i = 0; i < oldTreeLength; i++) {
|
|
689
680
|
oldKeyedList[oldTree[i].props.key] = i;
|
|
690
681
|
}
|
|
691
682
|
|
|
692
683
|
// Create an object that maps keys to indices in the new tree
|
|
693
|
-
let newKeyedList:
|
|
684
|
+
let newKeyedList: Record<string, number> = {};
|
|
694
685
|
for (let i = 0; i < newTreeLength; i++) {
|
|
695
686
|
newKeyedList[newTree[i].props.key] = i;
|
|
696
687
|
}
|
|
@@ -989,7 +980,7 @@ export function unmount() {
|
|
|
989
980
|
}
|
|
990
981
|
}
|
|
991
982
|
// This function takes in a DOM element or a DOM element selector and a component to be mounted on it.
|
|
992
|
-
export function mount(dom, component) {
|
|
983
|
+
export function mount(dom: string | DomElement, component: any) {
|
|
993
984
|
// Check if the 'dom' argument is a string. If it is, select the first element that matches the given selector.
|
|
994
985
|
// Otherwise, use the 'dom' argument as the container.
|
|
995
986
|
let container =
|