@nteract/commutable
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -162,2 +162,17 @@ "use strict"; | ||
function createImmutableMetadata(metadata) { | ||
return Immutable.Map(metadata).map(function (v, k) { | ||
if (k !== "tags") { | ||
return v; | ||
} | ||
if (Array.isArray(v)) { | ||
return Immutable.Set(v); | ||
} | ||
// The notebook spec requires that this field is an Array of strings | ||
return Immutable.Set(); | ||
}); | ||
} | ||
function createImmutableRawCell(cell) { | ||
@@ -168,3 +183,3 @@ // $FlowFixMe: Immutable | ||
source: demultiline(cell.source), | ||
metadata: Immutable.fromJS(cell.metadata) | ||
metadata: createImmutableMetadata(cell.metadata) | ||
}); | ||
@@ -178,3 +193,3 @@ } | ||
source: demultiline(cell.source), | ||
metadata: Immutable.fromJS(cell.metadata) | ||
metadata: createImmutableMetadata(cell.metadata) | ||
}); | ||
@@ -191,3 +206,3 @@ } | ||
execution_count: cell.execution_count, | ||
metadata: Immutable.fromJS(cell.metadata) | ||
metadata: createImmutableMetadata(cell.metadata) | ||
}); | ||
@@ -234,11 +249,12 @@ } | ||
function metadataToJS(immMetadata) { | ||
// $FlowFixMe these shouldn't be mixed types really | ||
return immMetadata.toJS(); | ||
} | ||
function markdownCellToJS(immCell) { | ||
// $FlowFixMe: With Immutable we can not properly type this | ||
var cell = immCell.toObject(); | ||
// $FlowFixMe: Fails now as a result of the above. | ||
return { | ||
cell_type: "markdown", | ||
source: remultiline(cell.source), | ||
metadata: Immutable.fromJS(cell.metadata) | ||
source: remultiline(immCell.get("source", "")), | ||
metadata: metadataToJS(immCell.get("metadata", Immutable.Map())) | ||
}; | ||
@@ -308,3 +324,2 @@ } | ||
// $FlowFixMe: Ditto above. | ||
return { | ||
@@ -315,3 +330,3 @@ cell_type: "code", | ||
execution_count: cell.execution_count, | ||
metadata: Immutable.fromJS(cell.metadata) | ||
metadata: metadataToJS(immCell.get("metadata", Immutable.Map())) | ||
}; | ||
@@ -324,7 +339,6 @@ } | ||
// $FlowFixMe: Ditto above. Cells should be Records. | ||
return { | ||
cell_type: "raw", | ||
source: remultiline(cell.source), | ||
metadata: Immutable.fromJS(cell.metadata) | ||
metadata: metadataToJS(immCell.get("metadata", Immutable.Map())) | ||
}; | ||
@@ -331,0 +345,0 @@ } |
{ | ||
"name": "@nteract/commutable", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "library for immutable notebook operations", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -241,2 +241,19 @@ /* @flow */ | ||
function createImmutableMetadata( | ||
metadata: JSONObject | ||
): Immutable.Map<string, any> { | ||
return Immutable.Map(metadata).map((v, k: string) => { | ||
if (k !== "tags") { | ||
return v; | ||
} | ||
if (Array.isArray(v)) { | ||
return Immutable.Set(v); | ||
} | ||
// The notebook spec requires that this field is an Array of strings | ||
return Immutable.Set(); | ||
}); | ||
} | ||
function createImmutableRawCell(cell: RawCell): ImmutableRawCell { | ||
@@ -247,3 +264,3 @@ // $FlowFixMe: Immutable | ||
source: demultiline(cell.source), | ||
metadata: Immutable.fromJS(cell.metadata) | ||
metadata: createImmutableMetadata(cell.metadata) | ||
}); | ||
@@ -259,3 +276,3 @@ } | ||
source: demultiline(cell.source), | ||
metadata: Immutable.fromJS(cell.metadata) | ||
metadata: createImmutableMetadata(cell.metadata) | ||
}); | ||
@@ -272,3 +289,3 @@ } | ||
execution_count: cell.execution_count, | ||
metadata: Immutable.fromJS(cell.metadata) | ||
metadata: createImmutableMetadata(cell.metadata) | ||
}); | ||
@@ -328,11 +345,12 @@ } | ||
function metadataToJS(immMetadata: Immutable.Map<string, mixed>): JSONObject { | ||
// $FlowFixMe these shouldn't be mixed types really | ||
return immMetadata.toJS(); | ||
} | ||
function markdownCellToJS(immCell: ImmutableCell): MarkdownCell { | ||
// $FlowFixMe: With Immutable we can not properly type this | ||
const cell: Cell = immCell.toObject(); | ||
// $FlowFixMe: Fails now as a result of the above. | ||
return { | ||
cell_type: "markdown", | ||
source: remultiline(cell.source), | ||
metadata: Immutable.fromJS(cell.metadata) | ||
source: remultiline(immCell.get("source", "")), | ||
metadata: metadataToJS(immCell.get("metadata", Immutable.Map())) | ||
}; | ||
@@ -412,3 +430,2 @@ } | ||
// $FlowFixMe: Ditto above. | ||
return { | ||
@@ -419,3 +436,3 @@ cell_type: "code", | ||
execution_count: cell.execution_count, | ||
metadata: Immutable.fromJS(cell.metadata) | ||
metadata: metadataToJS(immCell.get("metadata", Immutable.Map())) | ||
}; | ||
@@ -428,7 +445,6 @@ } | ||
// $FlowFixMe: Ditto above. Cells should be Records. | ||
return { | ||
cell_type: "raw", | ||
source: remultiline(cell.source), | ||
metadata: Immutable.fromJS(cell.metadata) | ||
metadata: metadataToJS(immCell.get("metadata", Immutable.Map())) | ||
}; | ||
@@ -435,0 +451,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
81702
1610