phosphorjs / phosphor

The PhosphorJS Library
BSD 3-Clause "New" or "Revised" License
1.04k stars 166 forks source link

Add datastore helper functions. #418

Closed ian-r-rose closed 4 years ago

ian-r-rose commented 4 years ago

This adds some helper utilities for getting, updating, and listening to data in the datastore.

These are currently statics in a Datastore namespace, since that's how I've been using them in JLab, but some of them could be moved onto the datastore class itself.

blink1073 commented 4 years ago

It looks like we need node typings in datastore:

$ tsc --build

lerna ERR! yarn run build exited 1 in '@phosphor/datastore'

lerna ERR! yarn run build stdout:

$ tsc --build

../signaling/src/index.ts(609,41): error TS2304: Cannot find name 'setImmediate'.
saulshanabrook commented 4 years ago

Hey @ian-r-rose here is an example of connecting a stateless example to a state store:

import React from 'react'
import { state, sequences } from 'cerebral'
import { connect } from '@cerebral/react'

export default connect(
  {
    foo: state`foo`,
    onClick: sequences`onClick`
  },
  function MyComponent({ foo, onClick }) {
    return <div onClick={() => onClick()}>{foo}</div>
  }
)

I'll take a look at this to see how the integration looks so far.

ian-r-rose commented 4 years ago

An example of specifying data locations for a widget to render a cell: https://github.com/ian-r-rose/jupyterlab/blob/e7f55cb40056cd75fda71aa43527cfbe1c79b14f/packages/cells/src/data.ts#L77-L91 In this case, the cell has a reference to a top-level record, as well as to a table of outputs.

An example of listening to for changes to particular fields: https://github.com/ian-r-rose/jupyterlab/blob/e7f55cb40056cd75fda71aa43527cfbe1c79b14f/packages/codemirror/src/editor.ts#L139-L154

An example of updating a particular record: https://github.com/ian-r-rose/jupyterlab/blob/e7f55cb40056cd75fda71aa43527cfbe1c79b14f/packages/cells/src/data.ts#L217-L226

blink1073 commented 4 years ago

Published @phosphor/datastore@0.8.0.

ian-r-rose commented 4 years ago

Thanks for the review @blink1073! My thinking on a good signature for these functions has shifted a bit over in jupyterlab/jupyterlab#6871, so I'll probably make a follow up.