How to use the OrderedSet function from immutable
Find comprehensive JavaScript immutable.OrderedSet code examples handpicked from public code repositorys.
immutable.OrderedSet is a data structure provided by the Immutable.js library that represents an ordered collection of unique values, allowing for efficient membership tests and insertion/deletion of items.
554 555 556 557 558 559 560 561 562 563 564 565
return structure; }; function subscribe(listeners, path, fn) { return listeners.updateIn(path.concat(LISTENER_SENTINEL), Immutable.OrderedSet(), function(old) { return old.add(fn); }); }
GitHub: ethical-jobs/redux
1336 1337 1338 1339 1340 1341 1342 1343 1344 1345
return state.set('fetching', false).set('error', false).update('entities', function (entities) { var selected = get_1(payload, 'data.entities', {}); return entities.mergeDeep(Immutable.fromJS(selected)); }).update('results', function (results) { var selected = get_1(payload, 'data.result', []); var payloadResults = Immutable.OrderedSet(selected); var resultsSet = Immutable.OrderedSet.isOrderedSet(results) ? results : results.toOrderedSet(); return resultsSet.union(payloadResults); }); }
How does immutable.OrderedSet work?
immutable.OrderedSet
works by providing a highly efficient data structure for managing ordered sets of unique values in JavaScript.
When a new OrderedSet
is created, it is backed by an underlying Map
object that tracks the index of each value in the set, allowing for constant-time lookups and efficient iteration over the set in its original order. OrderedSet
objects are also immutable, meaning that any operation that adds, removes, or modifies items in the set will return a new OrderedSet
object rather than modifying the original.
OrderedSet
objects provide a number of methods for working with the set's contents, including has
to check for membership, add
and delete
to add or remove items, and union
, intersect
, and subtract
to combine sets. OrderedSet
objects also have a number of convenient iterator methods, including map
, filter
, and reduce
.
By using immutable.OrderedSet
, JavaScript developers can efficiently manage ordered collections of unique values, enabling more efficient and flexible data processing and analysis.
351 352 353 354 355 356 357 358 359 360
new Set([new Set([1]), new Set([2])]), new Set([new Set([1]), new Set([3])]), ], [Immutable.Set([1, 2]), Immutable.Set()], [Immutable.Set([1, 2]), Immutable.Set([1, 2, 3])], [Immutable.OrderedSet([1, 2]), Immutable.OrderedSet([2, 1])], [new Map([[1, 'one'], [2, 'two']]), new Map([[1, 'one']])], [new Map([['a', 0]]), new Map([['b', 0]])], [new Map([['v', 1]]), new Map([['v', 2]])], [new Map([[['v'], 1]]), new Map([[['v'], 2]])],
+ 2 other calls in file
38 39 40 41 42 43 44 45 46 47 48 49
var gkx = require("./gkx"); var _require = require("immutable"), List = _require.List, Map = _require.Map, OrderedSet = _require.OrderedSet; var experimentalTreeDataSupport = gkx('draft_tree_data_support'); var NBSP = ' '; var SPACE = ' '; // used for replacing characters in HTML
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
const { OrderedSet } = require("immutable"); // create a new OrderedSet containing three values const set1 = OrderedSet(["apple", "banana", "cherry"]); // add a new value to the set const set2 = set1.add("date"); // remove a value from the set const set3 = set2.delete("banana"); // check if a value is in the set console.log(`Does the set contain "apple"? ${set3.has("apple")}`); // iterate over the set's values in order set3.forEach((value) => console.log(value));
In this example, we're using immutable.OrderedSet to create and manipulate an ordered set of unique string values. We first create a new OrderedSet object containing the values "apple", "banana", and "cherry", using the OrderedSet factory function and passing in an array of values. We then create a new OrderedSet object called set2 by adding a new value, "date", to set1 using the add method. We create a third OrderedSet object called set3 by removing the value "banana" from set2 using the delete method. We then use the has method to check whether set3 contains the value "apple", and log the result to the console. Finally, we use the forEach method to iterate over the values of set3 in their original order, logging each value to the console. When we run this code, it will output the following messages to the console: bash Copy code
35 36 37 38 39 40 41 42 43 44 45 46 47
var removeRangeFromContentState = require("./removeRangeFromContentState"); var splitBlockInContentState = require("./splitBlockInContentState"); var OrderedSet = Immutable.OrderedSet; /** * `DraftModifier` provides a set of convenience methods that apply * modifications to a `ContentState` object based on a target `SelectionState`. *
1855 1856 1857 1858 1859 1860 1861 1862 1863 1864
style }; }, blockRenderers: { 'code-block': block => { const blockStyles = immutable.OrderedSet(defaultPreTagStyling.map(v => v.join(': '))); return `<pre${getClassesAndStyles({ block, blockStyles })}>${buildHtmlForBlockText('', block, contentState)}</pre>`;
+ 9 other calls in file
immutable.Map is the most popular function in immutable (1575 examples)