Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.

Add an initial cell model #2

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"typings": "lib/index.d.ts",
"dependencies": {
"phosphor-observablelist": "^0.9.2",
"phosphor-signaling": "^1.1.2",
"phosphor-widget": "^0.9.13"
},
"devDependencies": {
Expand Down
177 changes: 177 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,180 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
'use-strict';

import {
IInputAreaViewModel
} from 'jupyter-js-input-area';

import {
IOutputAreaViewModel
} from 'jupyter-js-output-area';

import {
IObservableList
} from 'phosphor-observablelist';

import {
ISignal
} from 'phosphor-signaling';

import {
Widget
} from 'phosphor-widget';

import './index.css';


/**
* An enum which describes the type of cell.
*/
enum CellType {
/**
* The cell contains code input.
*/
Code,

/**
* The cell contains markdown.
*/
Markdown,

/**
* The cell contains raw text.
*/
Raw
}


/**
* The arguments object emitted with the `stateChanged` signal.
*/
export
interface ICellChangedArgs<T> {
name: string,
oldValue: T;
newValue: T;
}


/**
* An object which is serializable.
*/
export
interface ISerializable {
toJSON(): any;
fromJSON(data: any): void;
}


/**
* The definition of a model object for a base cell.
*/
interface IBaseCellViewModel {

/**
* The type of cell.
*/
type: CellType;

/**
* Tags applied to the cell.
*/
tags?: IObservableList<string>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we restrict string to a subset with reg-exes in typescript ? I think if so we should restrict to A-Za-z- (same for name). I think the restriction was already discussed and is informally agreed upon fro extension as each tag might be added as a class on the dom element of the cell.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would need to be asserted dynamically at runtime.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.e. not possible with the type system

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course for checking values at runtime. But I was more wondering if there was a syntax in the interface just for documentation purpose.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I confusing with JSON schema paternProperties.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with type.

For the metadat stuff, what about making the values be something like this:

interface ISerializable {
  toJson(): any;
  fromJson(data: any): void;
}

That at least encodes the fact that we expect the data to be serializable
to/from JSON?

On Tue, Nov 3, 2015 at 10:20 PM, Matthias Bussonnier <
[email protected]> wrote:

In src/index.ts
#2 (comment):

+/**

  • * The definition of a model object for a base cell.
  • */
    +interface IBaseCellViewModel {
    +
  • /**
  • * The type of cell.
  • */
  • cellType: CellType;
  • /**
  • * Tags applied to the cell.
  • */
  • tags?: IObservableList;

Never mind, I confusing with JSON schema paternProperties.


Reply to this email directly or view it on GitHub
https://github.com/jupyter/jupyter-js-cells/pull/2/files#r43839214.

Brian E. Granger
Associate Professor of Physics and Data Science
Cal Poly State University, San Luis Obispo
@ellisonbg on Twitter and GitHub
[email protected] and [email protected]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, the javascript JSON.stringify function looks for a toJSON() function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#toJSON()_behavior.


/**
* Get namespaced metadata about the cell.
*/
getMetadata(namespace: string) : IObservableMap<string, ISerializable>;

/**
* The input area of the cell.
*/
input: IInputAreaViewModel;

/**
* Whether a cell is deletable.
*/
deleteable: boolean;

/**
* Whether a cell is mergable.
*/
mergeable: boolean;

/**
* Whether a cell is splittable.
*/
splittable: boolean;

/**
* Whether a cell is rendered.
*/
rendered: boolean;

/**
* Whether the cell is marked for applying commands
*/
marked: boolean;

/**
* Run the cell.
*/
run(): void;
}


/**
* The definition of a code cell.
*/
export
interface ICodeCellViewModel extends IBaseCellViewModel {

/**
* A signal emitted when state of the cell changes.
*/
stateChanged: ISignal<ICodeCellViewModel, ICellChangedArgs<any>>;

output: IOutputAreaViewModel;
}


/**
* The definition of a raw cell.
*/
export
interface IRawCellViewModel extends IBaseCellViewModel {

/**
* A signal emitted when state of the cell changes.
*/
stateChanged: ISignal<IRawCellViewModel, ICellChangedArgs<any>>;

/**
* The raw cell format.
*/
format?: string;
}


/**
* The definition of a markdown cell.
*/
export
interface IMarkdownCellViewModel extends IBaseCellViewModel {

/**
* A signal emitted when state of the cell changes.
*/
stateChanged: ISignal<IMarkdownCellViewModel, ICellChangedArgs<any>>;
}



/**
* A model consisting of any valid cell type.
*/
export
type ICellViewModel = (
IRawCellViewModel | IMarkdownCellViewModel | ICodeCellViewModel
);