mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-21 06:31:28 +02:00
Refactor code with immutable-js in Model (#2077)
* Ugly Commit * Small Styling issues about immutable-js * Remove an unnecessary List
This commit is contained in:
committed by
Ian Storm Taylor
parent
dc95ad66a5
commit
48e5c6e04b
@@ -389,7 +389,7 @@ class Node {
|
|||||||
|
|
||||||
getBlocks() {
|
getBlocks() {
|
||||||
const array = this.getBlocksAsArray()
|
const array = this.getBlocksAsArray()
|
||||||
return new List(array)
|
return List(array)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -417,7 +417,7 @@ class Node {
|
|||||||
getBlocksAtRange(range) {
|
getBlocksAtRange(range) {
|
||||||
const array = this.getBlocksAtRangeAsArray(range)
|
const array = this.getBlocksAtRangeAsArray(range)
|
||||||
// Eliminate duplicates by converting to an `OrderedSet` first.
|
// Eliminate duplicates by converting to an `OrderedSet` first.
|
||||||
return new List(new OrderedSet(array))
|
return List(OrderedSet(array))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -454,7 +454,7 @@ class Node {
|
|||||||
|
|
||||||
getBlocksByType(type) {
|
getBlocksByType(type) {
|
||||||
const array = this.getBlocksByTypeAsArray(type)
|
const array = this.getBlocksByTypeAsArray(type)
|
||||||
return new List(array)
|
return List(array)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -607,16 +607,9 @@ class Node {
|
|||||||
path = this.resolvePath(path)
|
path = this.resolvePath(path)
|
||||||
if (!path) return null
|
if (!path) return null
|
||||||
|
|
||||||
const array = path.toArray()
|
const deep = path.flatMap(x => ['nodes', x])
|
||||||
let descendant = this
|
const ret = this.getIn(deep)
|
||||||
|
return ret
|
||||||
for (const index of array) {
|
|
||||||
if (!descendant) return null
|
|
||||||
if (!descendant.nodes) return null
|
|
||||||
descendant = descendant.nodes.get(index)
|
|
||||||
}
|
|
||||||
|
|
||||||
return descendant
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -782,7 +775,7 @@ class Node {
|
|||||||
|
|
||||||
getInlines() {
|
getInlines() {
|
||||||
const array = this.getInlinesAsArray()
|
const array = this.getInlinesAsArray()
|
||||||
const list = new List(array)
|
const list = List(array)
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -818,7 +811,7 @@ class Node {
|
|||||||
getInlinesAtRange(range) {
|
getInlinesAtRange(range) {
|
||||||
const array = this.getInlinesAtRangeAsArray(range)
|
const array = this.getInlinesAtRangeAsArray(range)
|
||||||
// Remove duplicates by converting it to an `OrderedSet` first.
|
// Remove duplicates by converting it to an `OrderedSet` first.
|
||||||
const list = new List(new OrderedSet(array))
|
const list = List(OrderedSet(array))
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -849,7 +842,7 @@ class Node {
|
|||||||
|
|
||||||
getInlinesByType(type) {
|
getInlinesByType(type) {
|
||||||
const array = this.getInlinesByTypeAsArray(type)
|
const array = this.getInlinesByTypeAsArray(type)
|
||||||
const list = new List(array)
|
const list = List(array)
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -953,8 +946,7 @@ class Node {
|
|||||||
|
|
||||||
getMarks() {
|
getMarks() {
|
||||||
const array = this.getMarksAsArray()
|
const array = this.getMarksAsArray()
|
||||||
const set = new Set(array)
|
return Set(array)
|
||||||
return set
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1012,7 +1004,7 @@ class Node {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
getMarksAtRange(range) {
|
getMarksAtRange(range) {
|
||||||
const marks = new Set(this.getOrderedMarksAtRange(range))
|
const marks = Set(this.getOrderedMarksAtRange(range))
|
||||||
return marks
|
return marks
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1025,8 +1017,7 @@ class Node {
|
|||||||
|
|
||||||
getMarksByType(type) {
|
getMarksByType(type) {
|
||||||
const array = this.getMarksByTypeAsArray(type)
|
const array = this.getMarksByTypeAsArray(type)
|
||||||
const set = new Set(array)
|
return Set(array)
|
||||||
return set
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1195,8 +1186,7 @@ class Node {
|
|||||||
|
|
||||||
getOrderedMarks() {
|
getOrderedMarks() {
|
||||||
const array = this.getMarksAsArray()
|
const array = this.getMarksAsArray()
|
||||||
const set = new OrderedSet(array)
|
return OrderedSet(array)
|
||||||
return set
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1272,8 +1262,7 @@ class Node {
|
|||||||
|
|
||||||
getOrderedMarksByType(type) {
|
getOrderedMarksByType(type) {
|
||||||
const array = this.getMarksByTypeAsArray(type)
|
const array = this.getMarksByTypeAsArray(type)
|
||||||
const set = new OrderedSet(array)
|
return OrderedSet(array)
|
||||||
return set
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1502,8 +1491,7 @@ class Node {
|
|||||||
|
|
||||||
getTexts() {
|
getTexts() {
|
||||||
const array = this.getTextsAsArray()
|
const array = this.getTextsAsArray()
|
||||||
const list = new List(array)
|
return List(array)
|
||||||
return list
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1537,9 +1525,7 @@ class Node {
|
|||||||
range = this.resolveRange(range)
|
range = this.resolveRange(range)
|
||||||
if (range.isUnset) return List()
|
if (range.isUnset) return List()
|
||||||
const { start, end } = range
|
const { start, end } = range
|
||||||
const list = new List(
|
const list = List(this.getTextsBetweenPositionsAsArray(start.key, end.key))
|
||||||
this.getTextsBetweenPositionsAsArray(start.key, end.key)
|
|
||||||
)
|
|
||||||
|
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
@@ -1914,7 +1900,7 @@ class Node {
|
|||||||
removeNode(path) {
|
removeNode(path) {
|
||||||
this.assertDescendant(path)
|
this.assertDescendant(path)
|
||||||
path = this.resolvePath(path)
|
path = this.resolvePath(path)
|
||||||
const deep = path.flatMap(x => List(['nodes', x]))
|
const deep = path.flatMap(x => ['nodes', x])
|
||||||
const ret = this.deleteIn(deep)
|
const ret = this.deleteIn(deep)
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
@@ -1954,7 +1940,7 @@ class Node {
|
|||||||
|
|
||||||
if (!path.size) return node
|
if (!path.size) return node
|
||||||
this.assertNode(path)
|
this.assertNode(path)
|
||||||
const deep = path.flatMap(x => List(['nodes', x]))
|
const deep = path.flatMap(x => ['nodes', x])
|
||||||
const ret = this.setIn(deep, node)
|
const ret = this.setIn(deep, node)
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
@@ -2120,7 +2106,7 @@ class Node {
|
|||||||
logger.deprecate(`0.35.0`, 'The `Node.getKeys` method is deprecated.')
|
logger.deprecate(`0.35.0`, 'The `Node.getKeys` method is deprecated.')
|
||||||
|
|
||||||
const keys = this.getKeysAsArray()
|
const keys = this.getKeysAsArray()
|
||||||
return new Set(keys)
|
return Set(keys)
|
||||||
}
|
}
|
||||||
|
|
||||||
getKeysAsArray() {
|
getKeysAsArray() {
|
||||||
|
Reference in New Issue
Block a user