Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Codebook Specs on Attach (Maybe Abandoned?) #478

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
update the codebook resource to generate a new one when it is attache…
…d to an upstream source
  • Loading branch information
darthtrevino committed Jan 10, 2023
commit c0e7d56aa4617e14cf515824100e45b8c5322265
18 changes: 16 additions & 2 deletions javascript/workflow/src/resources/Codebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import {
KnownProfile,
LATEST_CODEBOOK_SCHEMA,
} from '@datashaper/schema'
import { type TableContainer, applyCodebook } from '@datashaper/tables'
import {
type TableContainer,
applyCodebook,
generateCodebook,
} from '@datashaper/tables'
import type { Subscription } from 'rxjs'
import { type Observable, BehaviorSubject } from 'rxjs'

Expand Down Expand Up @@ -91,10 +95,20 @@ export class Codebook extends Resource implements TableTransformer {
}

private encodeTable = (t: Maybe<TableContainer>): Maybe<TableContainer> => {
if (t?.table == null || this.fields.length === 0) {
if (t?.table == null) {
// empty table? just return it
return t
} else if (this.fields.length === 0) {
// valid table but empty codebook? generate a new codebook
this._fields$.next(generateCodebook(t.table).fields)
}

if (this.fields.length === 0) {
// no codebook at this point? just return the table
return t
}

// apply the codebook to the table
const encodedTable = applyCodebook(
t.table,
this,
Expand Down