Skip to content

better client server segregation #9396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
"./internal": {
"default": "./src/internal/index.js"
},
"./internal/disclose-version": {
"default": "./src/internal/disclose-version.js"
"./internal/common/disclose-version": {
"default": "./src/internal/common/disclose-version.js"
},
"./internal/server": {
"default": "./src/internal/server/index.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export function client_component(source, analysis, options) {
];

if (options.discloseVersion) {
body.unshift(b.imports([], 'svelte/internal/disclose-version'));
body.unshift(b.imports([], 'svelte/internal/common/disclose-version'));
}

if (options.legacy.componentApi) {
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/client/block.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { current_block } from './runtime.js';
import { current_block } from '../common/runtime.js';

export const ROOT_BLOCK = 0;
export const IF_BLOCK = 1;
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/client/custom-element.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createClassComponent } from '../../legacy/legacy-client.js';
import { render_effect, destroy_signal } from './runtime.js';
import { render_effect, destroy_signal } from '../common/runtime.js';
import { open, close } from './render.js';
import { define_property } from './utils.js';

Expand Down
4 changes: 2 additions & 2 deletions packages/svelte/src/internal/client/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ import {
current_component_context,
pop,
schedule_task
} from './runtime.js';
} from '../common/runtime.js';
import {
current_hydration_fragment,
get_hydration_fragment,
hydrate_block_anchor,
set_current_hydration_fragment
} from './hydration.js';
import { array_from, define_property, get_descriptor, get_descriptors, is_array } from './utils.js';
import { is_promise } from '../common.js';
import { is_promise } from '../common/index.js';
import { bind_transition } from './transitions.js';

/** @type {Set<string>} */
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/client/transitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
effect,
managed_pre_effect,
untrack
} from './runtime.js';
} from '../common/runtime.js';
import { raf } from './timing.js';

const active_tick_animations = new Set();
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/client/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
DYNAMIC_ELEMENT_BLOCK,
SNIPPET_BLOCK
} from './block.js';
import { DERIVED, EFFECT, RENDER_EFFECT, SOURCE, PRE_EFFECT } from './runtime.js';
import { DERIVED, EFFECT, RENDER_EFFECT, SOURCE, PRE_EFFECT } from '../common/runtime.js';

// Put all internal types in this file. Once we convert to JSDoc, we can make this a d.ts file

Expand Down
18 changes: 0 additions & 18 deletions packages/svelte/src/internal/common.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PUBLIC_VERSION } from '../version.js';
import { PUBLIC_VERSION } from '../../version.js';

if (typeof window !== 'undefined')
// @ts-ignore
Expand Down
80 changes: 80 additions & 0 deletions packages/svelte/src/internal/common/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { get_or_init_context_map } from './runtime';

// eslint-disable-next-line @typescript-eslint/no-empty-function
export const EMPTY_FUNC = () => {};

// Adapted from https://github.com/then/is-promise/blob/master/index.js
// Distributed under MIT License https://github.com/then/is-promise/blob/master/LICENSE

/**
* @template [T=any]
* @param {any} value
* @returns {value is PromiseLike<T>}
*/
export function is_promise(value) {
return (
!!value &&
(typeof value === 'object' || typeof value === 'function') &&
typeof (/** @type {any} */ (value).then) === 'function'
);
}

/**
* Retrieves the context that belongs to the closest parent component with the specified `key`.
* Must be called during component initialisation.
*
* https://svelte.dev/docs/svelte#getcontext
* @template T
* @param {any} key
* @returns {T}
*/
export function getContext(key) {
const context_map = get_or_init_context_map();
return /** @type {T} */ (context_map.get(key));
}

/**
* Associates an arbitrary `context` object with the current component and the specified `key`
* and returns that object. The context is then available to children of the component
* (including slotted content) with `getContext`.
*
* Like lifecycle functions, this must be called during component initialisation.
*
* https://svelte.dev/docs/svelte#setcontext
* @template T
* @param {any} key
* @param {T} context
* @returns {T}
*/
export function setContext(key, context) {
const context_map = get_or_init_context_map();
context_map.set(key, context);
return context;
}

/**
* Checks whether a given `key` has been set in the context of a parent component.
* Must be called during component initialisation.
*
* https://svelte.dev/docs/svelte#hascontext
* @param {any} key
* @returns {boolean}
*/
export function hasContext(key) {
const context_map = get_or_init_context_map();
return context_map.has(key);
}

/**
* Retrieves the whole context map that belongs to the closest parent component.
* Must be called during component initialisation. Useful, for example, if you
* programmatically create a component and want to pass the existing context to it.
*
* https://svelte.dev/docs/svelte#getallcontexts
* @template {Map<any, any>} [T=Map<any, any>]
* @returns {T}
*/
export function getAllContexts() {
const context_map = get_or_init_context_map();
return /** @type {T} */ (context_map);
}
Loading