anthonyjoeseph / spectacles-ts

Practical Optics • Unfancy monocle-ts
99 stars 2 forks source link

JSDoc #26

Open anthonyjoeseph opened 2 years ago

anthonyjoeseph commented 2 years ago

examples from where?

ivklgn commented 2 years ago

@anthonyjoeseph this is good one https://codesandbox.io/s/spectacles-ts-experiments-krc1x9?file=/src/experiments.ts

but from tests is better

ivklgn commented 2 years ago

@anthonyjoeseph im ready to contribute jsdoc. what kind of format?

anthonyjoeseph commented 2 years ago

Oh wow that would be great! I think something modelled after fp-ts

/**
 * Sets a value at a particular path
 * 
 * If a value at the path doesn't exist, return O.none, otherwise wrap the result in O.some
 *
 * @example
 * import { pipe } from 'fp-ts/function'
 * import * as O from 'fp-ts/Option'
 * import { setOption } from 'spectacles-ts/set'
 * 
 * type Data = { a?: { b: number } }
 * 
 * assert.strictEqual(
 *   pipe(
 *     { a: { b: 123 } } as Data,
 *     setOption('a.b', 456)
 *   ),
 *   O.some({ a: { b: 456 } })
 * )
 * assert.strictEqual(
 *   pipe(
 *     {} as Data,
 *     setOption('a?.b', 456)
 *   ),
 *   0.none
 * )
 *
 * @since 1.0.7
 */

We should probably use docs-ts at some point to make sure that the examples actually compile