Skip to content

Commit

Permalink
change api
Browse files Browse the repository at this point in the history
  • Loading branch information
weizman committed Oct 9, 2024
1 parent fb55997 commit c9f2ec4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/native.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const {
getOwnPropertyDescriptor,
entries, create, hasOwn,
} = Object;
const { from, isArray } = Array;
const { from } = Array;
const {random } = Math;
const { clipboard } = navigator;

Expand Down Expand Up @@ -59,7 +59,7 @@ export {
getOwnPropertyDescriptor,
entries, create, hasOwn,
// Array
from, isArray,
from,
// Math
random,
}
2 changes: 1 addition & 1 deletion packages/react/demo/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function App() {

console.info('render marked', count);

const [token, copy] = toLavaDomeCapabilities(secret);
const {token, copy} = toLavaDomeCapabilities(secret);

return (
<div onClick={() => setCount(count+1)} >
Expand Down
10 changes: 4 additions & 6 deletions packages/react/src/lavadome.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useRef } from 'react'
import { LavaDome as LavaDomeCore } from "@lavamoat/lavadome-core"
import {create, hasOwn, WeakMap, get, set, isArray, at, Error, TypeError} from "@lavamoat/lavadome-core/src/native.mjs";
import {create, hasOwn, WeakMap, get, set, Error, TypeError} from "@lavamoat/lavadome-core/src/native.mjs";

const
tokenToCopyInvokerMap = new WeakMap(),
Expand Down Expand Up @@ -28,7 +28,7 @@ export const textToLavaDomeCapabilities = text => {
const token = textToTokenMap[text];
const copy = () => get(tokenToCopyInvokerMap, token)();

return [token, copy];
return {token, copy};
}

// we want to use the token as a useEffect dep, but we don't want to leak it to React
Expand Down Expand Up @@ -63,9 +63,7 @@ export const LavaDome = ({ token, unsafeOpenModeShadow }) => {
// form a span to act as the LavaDome host
<span ref={host}>
<LavaDomeShadow
host={host}
// accept both formats (token, or [token, copy])
token={isArray(token) ? at(token, 0) : token}
host={host} token={token}
unsafeOpenModeShadow={unsafeOpenModeShadow}
/>
</span>
Expand All @@ -82,8 +80,8 @@ function LavaDomeShadow({ host, token, unsafeOpenModeShadow }) {
// update lavadome secret text (given that the token is updated too)
useEffect(() => {
const lavadome = new LavaDomeCore(host.current, {unsafeOpenModeShadow});
set(tokenToCopyInvokerMap, token, lavadome.copy);
lavadome.text(text);
set(tokenToCopyInvokerMap, token, lavadome.copy);
}, [dep]);

return <></>;
Expand Down

0 comments on commit c9f2ec4

Please sign in to comment.