Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'immutable' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
assert.oequal(
await runAndGivePositions(indexes, {
orderBy: { field: 'createdAt' },
before: cursors.get(2),
}),
Range(0, 2),
'only before'
);
assert.oequal(
await runAndGivePositions(indexes, {
orderBy: { field: 'createdAt' },
after: cursors.get(1),
before: cursors.get(5),
}),
Range(2, 5),
'before and after'
);
// XXX(freiksenet, 2015-08-12): this is not strictly compliant to
// relay spec, that asks to not apply one of the cursors if they are
// disjoint.
assert.oequal(
await runAndGivePositions(indexes, {
orderBy: { field: 'createdAt' },
before: cursors.get(1),
after: cursors.get(5),
}),
List(),
'disjoint before and after'
);
});
const deepEqualValues = (a: any, b: any) => {
if (Iterable.isIterable(a)) {
return (
Iterable.isIterable(b) &&
a.count() === b.count() &&
a.every((value, key) => deepEqualValues(value, b.get(key)))
)
}
return deepEqual(a, b) // neither are immutable collections
}
const deepEqualValues = (a: any, b: any) => {
if (Iterable.isIterable(a)) {
return (
Iterable.isIterable(b) &&
a.count() === b.count() &&
a.every((value, key) => deepEqualValues(value, b.get(key)))
)
}
return deepEqual(a, b) // neither are immutable collections
}
updateAccountData(account) {
let options = account.get("options");
let proxy_account_id = options.get("voting_account");
if (proxy_account_id === "1.2.5") {
proxy_account_id = "";
}
let votes = options.get("votes");
let vote_ids = votes.toArray();
// remove workers
vote_ids = vote_ids.filter(id => {
return id.split(":")[0] != '2';
});
let vids = Immutable.Set(vote_ids);
ChainStore.getObjectsByVoteIds(vote_ids);
FetchChainObjects(ChainStore.getObjectByVoteID, vote_ids, 5000).then(vote_objs => {
//console.log( "Vote Objs: ", vote_objs );
let witnesses = new Immutable.List();
let committee = new Immutable.List();
let workers = new Immutable.Set();
vote_objs.forEach(obj => {
let account_id = obj.get("committee_member_account");
if (account_id) {
committee = committee.push(account_id);
} else if (account_id = obj.get("worker_account")) {
// console.log( "worker: ", obj );
// workers = workers.add(obj.get("id"));
} else if (account_id = obj.get("witness_account")) {
witnesses = witnesses.push(account_id);
}
// Validate whether the address is valid
let pattern = /^(0x)?[0-9a-fA-F]{40}$/
if (pattern.test(address)) {
return errors
} else {
return errors.push(
immutable.fromJS({
path,
message: `\
Contract address is invalid: ${address}
Must be 40 hexadecimal characters, with an optional '0x' prefix.`,
}),
)
}
}, immutable.List())
}
constructor(bridge: Bridge, mainStore: Object) {
super();
this.storeData = null;
this.storeDateSubscriptionCount = 0;
this.selectedQuery = null;
this.queries = new OrderedMap();
this._bridge = bridge;
this._mainStore = mainStore;
// initial population of the store
bridge.on('relay:store', data => {
this.storeData = data;
this.emit('storeData');
});
this.queriesByDataID = {};
// queries and mutations
bridge.on('relay:pending', pendingQueries => {
pendingQueries.forEach(pendingQuery => {
this.queries = this.queries.set(
pendingQuery.id,
new Map({
...pendingQuery,
status: 'pending',
function pathToKeySeq(path) {
// Remove trailing '/' etc.
path = Path.join(path, '.');
if (path === '.') {
return Immutable.Seq([]);
} else {
return Immutable.Seq(path.split('/'));
}
}
function init(code, bc, builtinBindings) {
var bcPointer = 0;
var p = im.Map({
exception: undefined,
code: code,
currentInstruction: undefined,
stack: im.Stack(),
callStack: im.List(), // can't be a stack because too much editing of head
scopes: im.List(),
heap: heapLib.create()
});
p = scope.addScope(p, im.Map(), undefined, false); // builtin scope, mouse, keyboard et
p = createTopLevelBindings(p, builtinBindings);
p = scope.addScope(p, im.Map(), BUILTIN_SCOPE_ID, true); // user top level scope
p = pushCallFrame(p, bc, bcPointer, USER_TOP_LEVEL_SCOPE_ID);
return p;
};
// COMMITTEE MEMBER OBJECT
else if( object.id.substring(0,committee_prefix.length) == committee_prefix )
{
this.committee_by_account_id.set( object.committee_member_account, object.id )
this.objects_by_vote_id.set( object.vote_id, object.id )
}
// ACCOUNT OBJECT
else if( object.id.substring(0,account_prefix.length) == account_prefix )
{
current = current.set( 'active', Immutable.fromJS( object.active ) );
current = current.set( 'owner', Immutable.fromJS( object.owner ) );
current = current.set( 'options', Immutable.fromJS( object.options ) );
current = current.set( 'whitelisting_accounts', Immutable.fromJS( object.whitelisting_accounts ) );
current = current.set( 'blacklisting_accounts', Immutable.fromJS( object.blacklisting_accounts ) );
current = current.set( 'whitelisted_accounts', Immutable.fromJS( object.whitelisted_accounts ) );
current = current.set( 'blacklisted_accounts', Immutable.fromJS( object.blacklisted_accounts ) );
this.objects_by_id = this.objects_by_id.set( object.id, current );
this.accounts_by_name = this.accounts_by_name.set( object.name, object.id )
}
// ASSET OBJECT
else if( object.id.substring(0,asset_prefix.length) == asset_prefix )
{
this.assets_by_symbol = this.assets_by_symbol.set( object.symbol, object.id )
let dynamic = current.get( 'dynamic' );
if( !dynamic ) {
let dad = this.getObject( object.dynamic_asset_data_id, true );
if( !dad )
dad = Immutable.Map()
if( !dad.get( 'asset_id' ) ) {
dad = dad.set( 'asset_id', object.id );
}
this.objects_by_id = this.objects_by_id.set( object.dynamic_asset_data_id, dad );
const CustomColorPickerInner = ColorWrap((props) => {
const styles = buildStyles(props);
// To fill space when customColors is less than 7.
const dummySwatchListLength = Math.max(MAX_CUSTOM_COLORS - props.customColors.size, 0);
const dummySwatchList = new List(Array(dummySwatchListLength)).map((_, i) => (
<span>
<div style="{styles.swatch}">
));
return (
<div style="{styles.picker}">
<div style="{styles.saturation}">
</div>
</div></div></span>