Skip to content
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

fix: recover stored value on init #26

Merged
merged 1 commit into from
Feb 5, 2024

Conversation

jorgecasar
Copy link
Contributor

Closes #25

@43081j
Copy link
Owner

43081j commented Feb 2, 2024

had a long think about it because i wasn't sure if it makes more sense in hostConnected, but i think you're right putting it in the constructor actually

could you also add a test?

basically similar to this suite:

suite('with default value', () => {
setup(async () => {
element = document.createElement('test-element') as TestElement;
controller = new LocalStorageController(element, 'test-key', [5, 6]);
element.controllers.push(controller);
element.template = () => html`${JSON.stringify(controller.value)}`;
document.body.appendChild(element);
await element.updateComplete;
});
test('initialises to default value', () => {
const storageValue = window.localStorage.getItem('test-key');
assert.equal(controller.value, [5, 6]);
assert.equal(element.shadowRoot!.textContent, '[5,6]');
assert.is(storageValue, '[5,6]');
});
});

it belongs in its own describe like that since you want to set test-key in your beforeEach (directly in local storage)

almost the same test, just don't pass a default. although it may be worth doing another where you do pass a default, and assert it uses the one from storage rather than the default

@jorgecasar jorgecasar force-pushed the 25-recover-stored-value branch 3 times, most recently from 5591c87 to 279318f Compare February 5, 2024 09:08
Copy link
Owner

@43081j 43081j left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me!

do love a PR which has more tests than code 😂 they will help out a lot though

@43081j 43081j merged commit 034fa9b into 43081j:main Feb 5, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Store doesn't get saved value on init
2 participants