Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagetypescript
export type Settings = { enabled: false; } | {
  /**
   * @title Enabled
   * @default false
   */
  enabled: true;
  
  /**
   * @title Some variable
   * @default “some-value”
   */
  some_variable: string;
};

Example with array of item:

Code Block
interface Item{
  /**
   * @title Name
   * @default ""
   */
  name: string;

  /**
   * @title Code
   * @default ""
   */
  code: string;
}

interface Items extends Array<Item>{}

export type Settings = { enabled: false } | {
  /**
   * @title Enabled
   */
  enabled: true;

  items: Items;
}

Note the conditional type here. In this example an instance of type Settings may have one of 2 interfaces: either enabled field has a value of false, or it is true and then some_variable field is required. When a settings form is rendered that would mean that some_variable field will be hidden, unless enabled field has a value of true (it will be rendered as a checkbox, so the checkbox must be checked).

...

Code Block
import { useSubscribe } from ‘@ombori/ga-messaging’;

const App = () => {

   ...
   const {count, setCount} = useState(0);
   const useSubscribe   useSubscribe('Test.Message', (msg) => {
     setCount(ct => ct + 1);
   }, [setCount]);

  return <div>Received {count} messages</div>
};

...

Code Block
import { usePublish } from ‘@ombori/ga-messaging’;

const App = () => {

   ...

   const publish = usePublish();
   const onClick = useCallback(() => {
     publish({type: ‘Hello.There’, some: ‘data here’}); 
   }, [broadcastpublish]);

  return <button onClick={onClick} />
};

...