import { BlLifeRecharge, BlLifeRechargeOptions } from '@life-payment/core';
|
import { inject, reactive, provide, ref } from 'vue';
|
import type { InjectionKey, UnwrapNestedRefs, Ref } from 'vue';
|
|
export type LifeRechargeContext = {
|
blLifeRecharge: UnwrapNestedRefs<BlLifeRecharge>;
|
};
|
|
const clientKey: InjectionKey<LifeRechargeContext> = Symbol('blLifeRecharge');
|
|
export type VueLifeRechargePluginOptions = {
|
blLifeRecharge: BlLifeRecharge;
|
};
|
|
function updateState(state: Record<string, unknown>, update: Record<string, any>): void {
|
Object.keys(state).forEach((key) => {
|
state[key] = update[key];
|
});
|
}
|
|
export const VueLifeRechargePlugin = {
|
install: (app: any, { blLifeRecharge }: VueLifeRechargePluginOptions) => {
|
const _blLifeRecharge = reactive(blLifeRecharge);
|
|
// blLifeRecharge.listener.addListener({
|
// update: (state) => {
|
// updateState(_blLifeRecharge, state);
|
// },
|
// });
|
|
app.provide(clientKey, {
|
blLifeRecharge: _blLifeRecharge,
|
});
|
},
|
};
|
|
export function useLifeRechargeContext() {
|
return inject(clientKey);
|
}
|