Skip to content

Commit 4b508ce

Browse files
committed
get rid of class_toggle_effect and style_effect
1 parent 3902291 commit 4b508ce

File tree

3 files changed

+9
-48
lines changed

3 files changed

+9
-48
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ function serialize_style_directives(style_directives, element_id, context, is_at
7474
directive.value === true
7575
? serialize_get_binding({ name: directive.name, type: 'Identifier' }, context.state)
7676
: serialize_attribute_value(directive.value, context)[1];
77-
const grouped = b.stmt(
77+
78+
const update = b.stmt(
7879
b.call(
7980
'$.style',
8081
element_id,
@@ -85,17 +86,6 @@ function serialize_style_directives(style_directives, element_id, context, is_at
8586
)
8687
)
8788
);
88-
const singular = b.stmt(
89-
b.call(
90-
'$.style_effect',
91-
element_id,
92-
b.literal(directive.name),
93-
b.arrow([], value),
94-
/** @type {import('estree').Expression} */ (
95-
directive.modifiers.includes('important') ? b.true : undefined
96-
)
97-
)
98-
);
9989

10090
const contains_call_expression =
10191
Array.isArray(directive.value) &&
@@ -104,11 +94,11 @@ function serialize_style_directives(style_directives, element_id, context, is_at
10494
);
10595

10696
if (!is_attributes_reactive && contains_call_expression) {
107-
state.init.push(singular);
97+
state.init.push(serialize_update(update));
10898
} else if (is_attributes_reactive || directive.metadata.dynamic || contains_call_expression) {
109-
state.update.push(grouped);
99+
state.update.push(update);
110100
} else {
111-
state.init.push(grouped);
101+
state.init.push(update);
112102
}
113103
}
114104
}
@@ -146,18 +136,15 @@ function serialize_class_directives(class_directives, element_id, context, is_at
146136
const state = context.state;
147137
for (const directive of class_directives) {
148138
const value = /** @type {import('estree').Expression} */ (context.visit(directive.expression));
149-
const grouped = b.stmt(b.call('$.class_toggle', element_id, b.literal(directive.name), value));
150-
const singular = b.stmt(
151-
b.call('$.class_toggle_effect', element_id, b.literal(directive.name), b.arrow([], value))
152-
);
139+
const update = b.stmt(b.call('$.class_toggle', element_id, b.literal(directive.name), value));
153140
const contains_call_expression = directive.expression.type === 'CallExpression';
154141

155142
if (!is_attributes_reactive && contains_call_expression) {
156-
state.init.push(singular);
143+
state.init.push(serialize_update(update));
157144
} else if (is_attributes_reactive || directive.metadata.dynamic || contains_call_expression) {
158-
state.update.push(grouped);
145+
state.update.push(update);
159146
} else {
160-
state.init.push(grouped);
147+
state.init.push(update);
161148
}
162149
}
163150
}

packages/svelte/src/internal/client/dom/elements/class.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,3 @@ export function class_toggle(dom, class_name, value) {
107107
dom.classList.remove(class_name);
108108
}
109109
}
110-
111-
/**
112-
* @param {Element} dom
113-
* @param {string} class_name
114-
* @param {() => boolean} value
115-
* @returns {void}
116-
*/
117-
export function class_toggle_effect(dom, class_name, value) {
118-
render_effect(() => {
119-
class_toggle(dom, class_name, value());
120-
});
121-
}

packages/svelte/src/internal/client/dom/elements/style.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,3 @@ export function style(dom, key, value, important) {
1717
style.setProperty(key, value, important ? 'important' : '');
1818
}
1919
}
20-
21-
/**
22-
* @param {HTMLElement} dom
23-
* @param {string} key
24-
* @param {() => string} value
25-
* @param {boolean} [important]
26-
* @returns {void}
27-
*/
28-
export function style_effect(dom, key, value, important) {
29-
render_effect(() => {
30-
const string = value();
31-
style(dom, key, string, important);
32-
});
33-
}

0 commit comments

Comments
 (0)