How to use @nteract/commutable - 10 common examples

To help you get started, we’ve selected a few @nteract/commutable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nteract / nteract / packages / reducers / __tests__ / document.spec.ts View on Github external
test("cleans up the outputs, pagers, and status", () => {
    const notebook = appendCellToNotebook(emptyNotebook, emptyCodeCell);
    const id = notebook.get("cellOrder").first();

    const initialState = makeDocumentRecord({
      filename: "test.ipynb",
      notebook,
      cellPagers: Immutable.Map({
        // Hokey data, we're just expecting it to be cleared
        id: Immutable.List(["a", "b"])
      }),
      transient: Immutable.Map({
        cellMap: Immutable.Map({
          id: Immutable.Map({
            status: "idle"
          })
        })
      })
github nteract / nteract / packages / reducers / __tests__ / document.spec.ts View on Github external
test("pastes a cell", () => {
    const firstId = uuid();
    const secondId = uuid();
    const thirdId = uuid();

    const originalState = makeDocumentRecord({
      notebook: Immutable.fromJS({
        cellOrder: [firstId, secondId, thirdId],
        cellMap: {
          [firstId]: emptyCodeCell,
          [secondId]: emptyCodeCell,
          [thirdId]: emptyCodeCell
        }
      }),
      cellFocused: secondId,
      copied: emptyCodeCell.set("source", "COPY PASTA")
    });

    // We will paste the cell after the focused cell
    const state = reducers(originalState, actions.pasteCell({}));

    // The third cell should be our copied cell
    const newCellId = state.getIn(["notebook", "cellOrder", 2]);
    expect(state.getIn(["notebook", "cellMap", newCellId])).toEqual(
      emptyCodeCell.set("source", "COPY PASTA")
    );

    expect(state.getIn(["notebook", "cellOrder"])).toEqual(
      Immutable.List([firstId, secondId, newCellId, thirdId])
    );

    // Ensure it's a new cell
github nteract / nteract / packages / reducers / __tests__ / document.spec.ts View on Github external
test("pastes a cell", () => {
    const firstId = uuid();
    const secondId = uuid();
    const thirdId = uuid();

    const originalState = makeDocumentRecord({
      notebook: Immutable.fromJS({
        cellOrder: [firstId, secondId, thirdId],
        cellMap: {
          [firstId]: emptyCodeCell,
          [secondId]: emptyCodeCell,
          [thirdId]: emptyCodeCell
        }
      }),
      cellFocused: secondId,
      copied: emptyCodeCell.set("source", "COPY PASTA")
    });

    // We will paste the cell after the focused cell
    const state = reducers(originalState, actions.pasteCell({}));

    // The third cell should be our copied cell
    const newCellId = state.getIn(["notebook", "cellOrder", 2]);
    expect(state.getIn(["notebook", "cellMap", newCellId])).toEqual(
      emptyCodeCell.set("source", "COPY PASTA")
    );

    expect(state.getIn(["notebook", "cellOrder"])).toEqual(
      Immutable.List([firstId, secondId, newCellId, thirdId])
    );

    // Ensure it's a new cell
github nteract / nteract / packages / reducers / __tests__ / document.spec.ts View on Github external
[firstId]: emptyCodeCell,
          [secondId]: emptyCodeCell,
          [thirdId]: emptyCodeCell
        }
      }),
      cellFocused: secondId,
      copied: emptyCodeCell.set("source", "COPY PASTA")
    });

    // We will paste the cell after the focused cell
    const state = reducers(originalState, actions.pasteCell({}));

    // The third cell should be our copied cell
    const newCellId = state.getIn(["notebook", "cellOrder", 2]);
    expect(state.getIn(["notebook", "cellMap", newCellId])).toEqual(
      emptyCodeCell.set("source", "COPY PASTA")
    );

    expect(state.getIn(["notebook", "cellOrder"])).toEqual(
      Immutable.List([firstId, secondId, newCellId, thirdId])
    );

    // Ensure it's a new cell
    expect(
      Immutable.Set([firstId, secondId, thirdId]).has(newCellId)
    ).toBeFalsy();
  });
});
github nteract / nteract / packages / reducers / __tests__ / document.spec.ts View on Github external
[firstId]: emptyCodeCell,
          [secondId]: emptyCodeCell,
          [thirdId]: emptyCodeCell
        }
      }),
      cellFocused: secondId,
      copied: emptyCodeCell.set("source", "COPY PASTA")
    });

    // We will paste the cell after the focused cell
    const state = reducers(originalState, actions.pasteCell({}));

    // The third cell should be our copied cell
    const newCellId = state.getIn(["notebook", "cellOrder", 2]);
    expect(state.getIn(["notebook", "cellMap", newCellId])).toEqual(
      emptyCodeCell.set("source", "COPY PASTA")
    );

    expect(state.getIn(["notebook", "cellOrder"])).toEqual(
      Immutable.List([firstId, secondId, newCellId, thirdId])
    );

    // Ensure it's a new cell
    expect(
      Immutable.Set([firstId, secondId, thirdId]).has(newCellId)
    ).toBeFalsy();
  });
});
github nteract / nteract / packages / reducers / __tests__ / document.spec.ts View on Github external
beforeEach(() => {
    // Arrange
    initialState = initialDocument.set(
      "notebook",
      Immutable.fromJS({
        cellOrder,
        cellMap: {
          [cellOrder[0]]: emptyCodeCell
            .setIn(["metadata", "jupyter", "outputs_hidden"], false)
            .setIn(["metadata", "jupyter", "source_hidden"], false),
          [cellOrder[1]]: emptyCodeCell
            .setIn(["metadata", "jupyter", "outputs_hidden"], true)
            .setIn(["metadata", "jupyter", "source_hidden"], false),
          [cellOrder[2]]: emptyCodeCell
            .setIn(["metadata", "jupyter", "source_hidden"], false)
            .setIn(["metadata", "jupyter", "outputs_hidden"], false),
          [cellOrder[3]]: emptyCodeCell
            .setIn(["metadata", "jupyter", "source_hidden"], true)
            .setIn(["metadata", "jupyter", "outputs_hidden"], false)
        }
      })
    );
  });
github nteract / nteract / packages / reducers / __tests__ / document.spec.ts View on Github external
// Arrange
    initialState = initialDocument.set(
      "notebook",
      Immutable.fromJS({
        cellOrder,
        cellMap: {
          [cellOrder[0]]: emptyCodeCell
            .setIn(["metadata", "jupyter", "outputs_hidden"], false)
            .setIn(["metadata", "jupyter", "source_hidden"], false),
          [cellOrder[1]]: emptyCodeCell
            .setIn(["metadata", "jupyter", "outputs_hidden"], true)
            .setIn(["metadata", "jupyter", "source_hidden"], false),
          [cellOrder[2]]: emptyCodeCell
            .setIn(["metadata", "jupyter", "source_hidden"], false)
            .setIn(["metadata", "jupyter", "outputs_hidden"], false),
          [cellOrder[3]]: emptyCodeCell
            .setIn(["metadata", "jupyter", "source_hidden"], true)
            .setIn(["metadata", "jupyter", "outputs_hidden"], false)
        }
      })
    );
  });
github nteract / hydrogen / spec / store / index-spec.js View on Github external
it("should return a fully-fledged notebook when the file isn't empty", () => {
      const source1 = 'print("Hola World! I <3 ZMQ!")';
      const source2 = "2 + 2";
      editor.setText(`# %%\n${source1}\n# %%\n${source2}\n`);
      store.updateEditor(editor);
      const codeCell1 = commutable.emptyCodeCell.set("source", source1);
      const codeCell2 = commutable.emptyCodeCell.set("source", source2);
      // The outputted notebook will have three cells because currently a cell
      // is always created before the first `# %%`
      let nb = commutable.appendCellToNotebook(
        commutable.emptyNotebook,
        codeCell1
      );
      nb = commutable.appendCellToNotebook(nb, codeCell2);
      expect(store.notebook).toEqual(commutable.toJS(nb));
    });
github nteract / hydrogen / spec / store / index-spec.js View on Github external
it("should export markdown to markdown cells", () => {
      const source1 = 'print("Hola World! I <3 ZMQ!")';
      const source2 = "2 + 2";
      editor.setText(`# %%\n${source1}\n# %% markdown\n${source2}\n`);
      store.updateEditor(editor);
      const codeCell = commutable.emptyCodeCell.set("source", source1);
      const markdownCell = commutable.emptyMarkdownCell.set("source", source2);
      // The outputted notebook will have three cells because currently a cell
      // is always created before the first `# %%`
      let nb = commutable.appendCellToNotebook(
        commutable.emptyNotebook,
        codeCell
      );
      nb = commutable.appendCellToNotebook(nb, markdownCell);
      expect(store.notebook).toEqual(commutable.toJS(nb));
    });
  });
github nteract / hydrogen / spec / store / index-spec.js View on Github external
it("should return an empty notebook for empty file", () => {
      store.updateEditor(editor);
      // Build a notebook with one code cell.
      const nb = commutable.emptyNotebook;
      expect(store.notebook).toEqual(commutable.toJS(nb));
    });