Skip to content

Commit

Permalink
Merge pull request #533 from microbit-foundation/523-fix-competing-pe…
Browse files Browse the repository at this point in the history
…rsistantwritables

523 fix competing persistantwritables
  • Loading branch information
r59q authored Oct 9, 2024
2 parents 800a07e + 57aeb4b commit b8b121c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 166 deletions.
4 changes: 2 additions & 2 deletions src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import { init, locale, register } from 'svelte-i18n';
export { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import { persistantWritable } from './script/stores/storeUtil';
import browserLang from 'browser-lang';
import PersistantWritable from './script/repository/PersistantWritable';

register('en', () => import('./messages/ui.en.json'));
register('da', () => import('./messages/ui.da.json'));
Expand All @@ -18,7 +18,7 @@ const initialLocale = browserLang({
fallback: 'en',
});

const persistantLocale = persistantWritable('lang', initialLocale);
const persistantLocale = new PersistantWritable(initialLocale, 'lang');

locale.subscribe(newLocal => {
if (newLocal) {
Expand Down
10 changes: 5 additions & 5 deletions src/script/stores/connectionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
*/

import { get, type Writable } from 'svelte/store';
import { persistantWritable } from './storeUtil';
import { MBSpecs } from 'microbyte';
import PersistantWritable from '../repository/PersistantWritable';
// Todo: Rename file to a more appropriate name
// Pattern for connecting to input microbit
export const btPatternInput: Writable<boolean[]> = persistantWritable<boolean[]>(
'btPatternInput',
export const btPatternInput: Writable<boolean[]> = new PersistantWritable<boolean[]>(
Array<boolean>(25).fill(false),
'btPatternInput',
);

// Pattern for connecting to output microbit
export const btPatternOutput: Writable<boolean[]> = persistantWritable<boolean[]>(
'btPatternOutput',
export const btPatternOutput: Writable<boolean[]> = new PersistantWritable<boolean[]>(
Array<boolean>(25).fill(false),
'btPatternOutput',
);

export const isInputPatternValid = () => {
Expand Down
11 changes: 7 additions & 4 deletions src/script/stores/knnConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
*
* SPDX-License-Identifier: MIT
*/
import { persistantWritable } from './storeUtil';
import StaticConfiguration from '../../StaticConfiguration';
import PersistantWritable from '../repository/PersistantWritable';

export type KNNSettings = {
k: number;
};

export const knnConfig = persistantWritable<KNNSettings>('knnConfig', {
k: StaticConfiguration.defaultKnnNeighbourCount,
});
export const knnConfig = new PersistantWritable(
{
k: StaticConfiguration.defaultKnnNeighbourCount,
},
'knnConfig',
);
155 changes: 0 additions & 155 deletions src/script/stores/storeUtil.ts

This file was deleted.

0 comments on commit b8b121c

Please sign in to comment.