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

Vue: Fix memory allocation for useAuthenticator composable #1052

Merged
merged 3 commits into from
Dec 28, 2021
Merged
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
5 changes: 5 additions & 0 deletions .changeset/gorgeous-ways-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/ui-vue': patch
---

Added wrapper for useAuthenticator to handle better memory usage
1 change: 1 addition & 0 deletions packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"dependencies": {
"@aws-amplify/ui": "3.0.5",
"@vueuse/core": "^7.4.1",
"@xstate/vue": "^0.8.0",
"qrcode": "^1.4.4"
},
Expand Down
7 changes: 6 additions & 1 deletion packages/vue/src/composables/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ref, reactive, Ref, watchEffect } from 'vue';
import { getServiceFacade } from '@aws-amplify/ui';
import { facade } from './useUtils';
import { InterpretService } from '@/components';
import { createSharedComposable } from '@vueuse/core';
Copy link
Contributor

Choose a reason for hiding this comment

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

That's an awesome library 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is! Lot's of great utilities in it!


const service = ref() as Ref<InterpretService>;
let useAuthenticatorValue = reactive({ ...facade, send: '', state: '' }) as any;
Expand All @@ -14,14 +15,18 @@ export const useAuth = (serv?: InterpretService) => {
return useActor(service.value);
};

export const useAuthenticator = () => {
const useInternalAuthenticator = () => {
createValues();
watchEffect(() => {
createValues();
});
return useAuthenticatorValue;
};

export const useAuthenticator = createSharedComposable(
useInternalAuthenticator
);

function createValues() {
if (!service.value) return;

Expand Down
20 changes: 20 additions & 0 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.