zim-gamshooks
TypeScript icon, indicating that this package has built-in type declarations

0.8.1 • Public • Published

ZIM GAMS Hooks

Short Description

Hooks for simplifying usage with GAMS.

Included hooks / short

GAMS data exchange

  1. useJsGlobal -> handles data exchange using global js variables
  2. useDatastream -> handles data exchange via requesting against a datastream of GAMS digital objects.
  3. useQueryObject -> handles construction of gams query-object sparql urls.

GAMS related client side calculations

  1. useDrilldown -> Client side calculation of faceted drilldown. (= Counting assigned tags)
  2. usePagination -> client side pagination represanting pages / chunks as tuples.

Typings

  • import from main entry point "zim-gamshooks"

Demos & Examples

Handling Gams data exchange

const GamsHooksDemo: React.FC = () => {

  // hook returns data and gui prop of global variable.
  // define type of returned property via ts
  const { data, gui }: {data: string, gui: string} = useJsGlobal("demo_conf");

  // use datastream works the same (awaits global json at a gams-object)
  // empty will request current pid object
  const dsData = useDatastream();
  
  // configure via params
  const dsData2 = useDatastream("context:fercan");
  const dsData3 = useDatastream("context:fercan", "MY_DATASTREAM_NAME");
  //       

  // example for requesting different datastreams depending on object.
  // assign datastream name as second param - do conditional logic to provide name.
  const example = useDatastream(null, window.location.href.includes("mode_main") ? "MAIN_DATASTREAM" : "SECONDARY_DATASTREAM");
  // use returned values.


  // example usage of useQueryObject hook
  const { buildQuery, toggleSparqlParam } = useQueryObject("context:derla");


  return (
    <div>
      {data ? <p>Data applied!</p> : null}
      <p>{data}</p>
    </div>
  )
};

export default GamsHooksDemo;

GAMS related client side ops

useDrilldown

// inside React component

// use hook 
const { drillDown, toggleTag, tagCounts } = gamsHooks.useDrilldown(props.drillDown.data);

Utility functions - gamsUtils

  • collection of utility methods used for gams development.

Contribute

Useful Resources

Create react app and useful stuff:

Important Scripts

# locally build publishable lib folder
# this folder will be published by npm publish later on
# make sure that in tsconfig.json -> noEmit is set to false!
npm run npm:build

# login to npm before
npm login

# apply new version
npm version x.y.z

# then publish to npmjs 
npm publish

Package Sidebar

Install

npm i zim-gamshooks

Weekly Downloads

9

Version

0.8.1

License

MIT

Unpacked Size

51 kB

Total Files

20

Last publish

Collaborators

  • stoff_sebi