Persist key default to kebab-case

This commit is contained in:
Ben Croker 2025-03-21 21:47:28 -06:00
parent ea74aa41a5
commit 09bd26ccd2
No known key found for this signature in database
GPG Key ID: 09D799816F1CF332
8 changed files with 31 additions and 28 deletions

View File

@ -11,11 +11,11 @@ Each tagged version of Datastar is accompanied by a release note. Read the [rele
- Updated Idiomorph to version [0.7.3](https://github.com/bigskysoftware/idiomorph/releases/tag/v0.7.3).
- Classes used in `data-class-*` attributes now default to kebab-case ([#761](https://github.com/starfederation/datastar/issues/761)).
- Events used in `data-on-*` attributes now default to kebab-case ([#761](https://github.com/starfederation/datastar/issues/761)).
- Keys used in `data-persist-*` attributes now default to kebab-case.
- The `datastar-sse` event is now dispatched on the element itself ([#761](https://github.com/starfederation/datastar/issues/761)).
- The NPM package now also exports all official plugins and bundles ([#742](https://github.com/starfederation/datastar/issues/742)).
- The NPM package now also exports all plugins and bundles ([#742](https://github.com/starfederation/datastar/issues/742)).
- Data attributes with plugin names in their prefix are no longer processed ([#771](https://github.com/starfederation/datastar/issues/771)).
- The alias used in the aliased bundle has been renamed to `star` (`data-star-*`) ([#772](https://github.com/starfederation/datastar/issues/772)).
- The indicator signal is not set to `false` when an SSE error occurs.
### Fixed

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ import {
type NestedValues,
PluginType,
} from '../../../../engine/types'
import { modifyCasing, trimDollarSignPrefix } from '../../../../utils/text'
import { kebab, modifyCasing, trimDollarSignPrefix } from '../../../../utils/text'
const SESSION = 'session'
@ -18,9 +18,12 @@ export const Persist: AttributePlugin = {
name: 'persist',
mods: new Set([SESSION]),
onLoad: ({ key, effect, mods, signals, value }) => {
key = modifyCasing(key, mods)
if (key === '') {
key = DATASTAR
} else {
// Default to kebab-case and allow modifying
key = kebab(key)
key = modifyCasing(key, mods)
}
const storage = mods.has(SESSION) ? sessionStorage : localStorage

4
sdk/go/consts.go generated
View File

@ -7,8 +7,8 @@ import "time"
const (
DatastarKey = "datastar"
Version = "1.0.0-beta.9"
VersionClientByteSize = 39626
VersionClientByteSizeGzip = 14840
VersionClientByteSize = 39632
VersionClientByteSizeGzip = 14845
//region Default durations

View File

@ -406,8 +406,8 @@ If a key is provided, it will be used as the key when saving in storage, otherwi
Modifiers allow you to modify the key and storage target.
- `__case` - Converts the casing of the key.
- `.camel` - Camel case: `myKey` (default)
- `.kebab` - Kebab case: `my-key`
- `.camel` - Camel case: `myKey`
- `.kebab` - Kebab case: `my-key` (default)
- `.snake` - Snake case: `my_key`
- `.pascal` - Pascal case: `MyKey`
- `__session` - Persists signals in Session Storage.