Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Feb 6, 2025
1 parent b4375c4 commit e8a5b15
Showing 1 changed file with 11 additions and 92 deletions.
103 changes: 11 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,113 +7,32 @@
[![NPM version](https://img.shields.io/npm/v/@discoveryjs/discovery.svg)](https://www.npmjs.com/package/@discoveryjs/discovery)
[![Twitter](https://badgen.net/badge/follow/@js_discovery?icon=twitter)](https://twitter.com/js_discovery)

Hackable JSON discovery tool
A framework for ad hoc JSON data analysis, shareable server-less reports and dashboards.

> Documentation in progress...
You also can use Discovery.js as an [advanced viewer for a JSON]() right on the GitHub or as an extension for a browser (Chrome, Edge, Firefox) – [JsonDiscovery](https://github.com/discoveryjs/JsonDiscovery).

## Articles
<img width="1340" alt="image" src="https://github.com/user-attachments/assets/e8ea62fd-1160-4d7e-a296-b3484edd6ec2" />

- [Discovery.js tutorials: quick start](https://dev.to/rdvornov/discovery-js-tutorials-quick-start-m3k)
- [JsonDiscovery: Changing a way we’re viewing JSON in a browser](https://blog.usejournal.com/changing-a-way-were-viewing-json-in-a-browser-51eda9103fa2)

## Examples of usage
## Built using Discovery.js

- [JsonDiscovery](https://github.com/discoveryjs/browser-extension-json-discovery) – Chrome/Firefox browser extension built on Discovery which allows to discover a JSON document and make reports
- [Statoscope](https://github.com/statoscope/statoscope) – a toolkit to analyze and validate webpack bundle
- [CPUpro](https://github.com/lahmatiy/cpupro) – rethinking of CPU profile analysis
- [CSS syntax reference](https://csstree.github.io/docs/syntax/) ([source](https://github.com/csstree/docs/tree/master/src/syntax))
- [Jora Docs](https://discoveryjs.github.io/jora/) – Jora query language and engine documentation and playground
- [CSSWG spec drafts index](https://csstree.github.io/csswg-drafts-index/) ([source](https://github.com/csstree/csswg-drafts-index))

## Articles

- [Discovery.js tutorials: quick start](https://dev.to/rdvornov/discovery-js-tutorials-quick-start-m3k)
- [JsonDiscovery: Changing a way we’re viewing JSON in a browser](https://blog.usejournal.com/changing-a-way-were-viewing-json-in-a-browser-51eda9103fa2)

## Related projects

- [Discovery CLI](https://github.com/discoveryjs/discovery-cli) – CLI tools to serve & build projects based on Discovery.js
- [JsonDiscovery](https://github.com/discoveryjs/browser-extension-json-discovery) – Chrome/Firefox browser extension built on Discovery which allows to discover a JSON document and make reports
- [Jora](https://github.com/discoveryjs/jora) – data query language
- [Jora CLI](https://github.com/discoveryjs/jora-cli) – a tool to process JSON data using Jora in command line interface

## Plugins

- [@discoveryjs/view-plugin-highcharts](https://github.com/discoveryjs/view-plugin-highcharts)[Highcharts](https://github.com/highcharts/highcharts) plugin

## Install

```
> npm install @discoveryjs/discovery
```

## Base concepts

**Model** goes through `data->prepare->render` chain. Data can be modified with `prepare` function and rendered by various views and its combinations.

**View** is a function(el, config, data, context) where:

* `el` - DOM-element in which view will be rendered
* `config` - configuration of view
* `data` - data to render
* `context` - contains of model data, metaifo (createdAt, etc), router (optional), any user defined or view defined additional data

**Page** is a root view function(el, data, context). Similar to view it has all of its arguments except config.

### Page

To define a page you should call `discovery.page.define(pageId, render(el, data, context), options)` where:

* `pageId` - unique page identifier
* `render` - page render function described above
* `options` - object with options:
* `reuseEl` - do not clear container before render page (skiped for first render or pageId change)
* `init` - invokes on first page render or pageId change
* `keepScrollOffset` - dont scroll to page top if `pageId` didn't changed since last page render
* `encodeParams`
* `decodeParams`

Other handy methods for working with page:

* `discovery.renderPage()`
* `discovery.setPage(pageId, pageRef, renderParam)`, `discovery.setPageParams(renderParams)` triggers `renderPage()`
* `discovery.getPageContext()` gets context of page

### Special pages

There are some built-in special pages:

* `default`
* `report`
* `not-found`

You can override this pages with `page.define()` method

### View

To define new view just call `discovery.view.define(viewId, render, options)` where:
* `viewId` - unique view identifier
* `render` - function(el, config, data, context) or view definition object
* `options` - object with following fields:
* `tag` - a tag name for a view container element. When value is `false` or `null` then `DocumentFragment` is used as a container

You can render your view with `discovery.view.render(el, view, data, context)` where:

* `view` can be string `viewId`, `ViewDefinition` or `Array<ViewDefinition>` viewId will expand to `{ view: viewId }`.
> Also you can specify `view` as `viewId:query`, that will give you handy shortcut to `{ view: viewId, data: query }`
* `viewDefinition` object with view definition settings:
* `view`: string `viewId`
* `when`: query, will be coerced to Boolean (but empty arrays and objects will coerce to `false`)
* `data`: query (will be described later)
* Also there can be view specific additional fields

### Special views

Also special built-in `sidebar` view is available you can override this view with `view.define`

### Queries

As a query you can specify string which will be processed by [Jora](https://github.com/lahmatiy/jora) so your data will be a result of following flow:

```
jora(value) -> function(data, context) -> data
```

Or you can use `function(data, context)` as query as well. Also you can use any data as query right away.

## License

MIT

0 comments on commit e8a5b15

Please sign in to comment.