immutable#OrderedMap TypeScript Examples
The following examples show how to use
immutable#OrderedMap.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ViewportProfile.ts From apl-suggester with Apache License 2.0 | 6 votes |
VIEWPORT_PROFILE_METADATA : OrderedMap<string, IViewportProfile> = OrderedMap({
hubRound : hubRound as IViewportProfile,
hubLandscapeSmall : hubLandscapeSmall as IViewportProfile,
hubLandscapeMedium : hubLandscapeMedium as IViewportProfile,
hubLandscape : HUB_LANDSCAPE,
hubLandscapeExtraLarge : hubLandscapeExtraLarge as IViewportProfile,
hubPortraitMedium : hubPortraitMedium as IViewportProfile,
tvFullscreen : tvFullscreen as IViewportProfile,
mobileSmall : mobileSmall as IViewportProfile,
mobileMedium : mobileMedium as IViewportProfile,
mobileLarge : mobileLarge as IViewportProfile
})
Example #2
Source File: storeBuildScopeTree.ts From ui-schema with MIT License | 6 votes |
storeBuildScopeTree = <S extends UIStoreType>(storeKeys: StoreKeys, scope: keyof UIStoreStateData, store: S, nestKey: string | undefined = undefined, ordered: boolean = false): S => {
const relativeList: (string | number)[] = [scope]
if (nestKey) {
storeKeys = addNestKey(nestKey, storeKeys)
}
storeKeys.forEach(key => {
if (typeof key === 'undefined') return
const value = store.getIn(relativeList)
if (
(
!List.isList(value) &&
!Map.isMap(value) &&
// @ts-ignore
!Record.isRecord(value)
) ||
(typeof key === 'number' && !List.isList(value))
) {
store = store.setIn(
relativeList,
typeof key === 'number' ? List() : ordered ? OrderedMap() : Map()
)
}
// the current iteration must have the "parents" relative storeKeys, not it's own,
// thus doesn't do the last entry inside the tree, that one must be handled by the widget/onChange handler
relativeList.push(key)
})
return store
}
Example #3
Source File: immutable.ts From capture-lite with GNU General Public License v3.0 | 6 votes |
export function sortObjectDeeplyByKey(
map: SortableMap
): OrderedMap<string, any> {
return OrderedMap(map)
.sortBy((_, key) => key)
.map(value =>
value instanceof Object ? sortObjectDeeplyByKey(value) : value
);
}
Example #4
Source File: material-ui-split.tsx From ui-schema with MIT License | 6 votes |
Main = () => {
const [showValidity, setShowValidity] = React.useState(false)
const [store, setStore] = React.useState((): UIStoreType => createStore(OrderedMap()))
const onChange: onChangeHandler = React.useCallback((actions) => {
setStore((prevStore: UIStoreType) => {
return storeUpdater(actions)(prevStore)
})
}, [setStore])
return <React.Fragment>
<Grid item xs={12}>
<UIStoreProvider<CustomConfig>
store={store}
onChange={onChange}
showValidity={showValidity}
//doNotDefault
>
<GridStack<{ rootContext?: InjectSplitSchemaRootContext }>
isRoot
schema={schemaData}
rootContext={rootContext}
/>
<MuiSchemaDebug schema={schemaData}/>
</UIStoreProvider>
<div style={{width: '100%'}}>
<Button onClick={() => setShowValidity(!showValidity)}>validity</Button>
<div>
{isInvalid(store.getValidity()) ? 'invalid' : 'valid'}
</div>
</div>
</Grid>
</React.Fragment>
}
Example #5
Source File: add_empty_block_to_end.ts From deepnotes-editor with MIT License | 6 votes |
/**
* Will add a child to the given parentBlockKey after all of it's children.
* If the parentBlockKey has no children, it will create a new child and add
* that.
*/
function appendChild(
blockMap: BlockMap,
parentBlockKey: string,
blockToAdd: ContentBlock
) {
const blockWithItsChildren = getBlocksWithItsDescendants(
blockMap,
parentBlockKey
);
let blockToInsertAfterKey = parentBlockKey;
const parentId = parentBlockKey;
let pos = getPosNum(1);
// if the block has some children
if (blockWithItsChildren && blockWithItsChildren.count() > 1) {
blockToInsertAfterKey = blockWithItsChildren.last().getKey();
pos = getPosAfter(blockWithItsChildren.last().getIn(['data', 'pos']));
}
return insertBlocksAfter(
blockMap,
OrderedMap({
[blockToAdd.getKey()]: blockToAdd
.setIn(['data', 'parentId'], parentId)
.setIn(['data', 'pos'], pos) as ContentBlock,
}),
blockToInsertAfterKey
);
}
Example #6
Source File: RequiredValidator.test.ts From ui-schema with MIT License | 5 votes |
describe('requiredValidator', () => {
test.each(([
[List(['name']), List(['name']), true],
[List(['name']), List(['street']), false],
[undefined, 'name', false],
[undefined, 'name', false],
]) as [List<string> | undefined, string, boolean][])(
'.should(%j, %s)',
(requiredList, storeKeys, expectedValid) => {
expect(requiredValidator.should({
requiredList: requiredList,
storeKeys,
})).toBe(expectedValid)
}
)
test.each([
[
'string',
'text1',
ERROR_NOT_SET,
true,
false,
], [
'string',
2,
ERROR_NOT_SET,
true,
false,
], [
'string',
'2',
ERROR_NOT_SET,
true,
false,
], [
'string',
'',
ERROR_NOT_SET,
false,
true,
], [
'string',
undefined,
ERROR_NOT_SET,
false,
true,
],
])(
'.handle(%j, %s)',
(type, value, error, expectedValid, expectedError) => {
const result = requiredValidator.handle({
schema: OrderedMap({type}),
value,
errors: createValidatorErrors(),
valid: true,
})
expect(result.valid).toBe(expectedValid)
expect(result.errors.hasError(error)).toBe(expectedError)
}
)
test(
'.noHandle(%j, %s)',
() => {
const result = requiredValidator.noHandle()
expect(result.required).toBe(false)
}
)
})
Example #7
Source File: ViewportProfile.ts From apl-suggester with Apache License 2.0 | 5 votes |
/**
* Get viewport profiles.
* @returns {OrderedMap<string, IViewportProfile>}
*/
export function getViewportProfiles() : OrderedMap<string, IViewportProfile> {
return VIEWPORT_PROFILE_METADATA;
}
Example #8
Source File: storeActionReducers.ts From ui-schema with MIT License | 5 votes |
storeActionReducers = <S extends UIStoreType = UIStoreType, D extends UIStoreUpdaterData = UIStoreUpdaterData, A extends UIStoreActions<S, D> = UIStoreActions<S, D>>(
action: A
): UIStoreUpdaterFn<D> | D => {
switch (action.type) {
case 'list-item-add':
return ({value = List(), internal = Map(), ...r}) => {
if ('itemValue' in action) {
value = value.push(action.itemValue)
} else {
const schema = action.schema
const items = schema.get('items')
const type = schema.getIn(['items', 'type']) as SchemaTypesType
value = value.push(
// todo: multi type support #68
type === 'object' ? OrderedMap() :
// todo: handle tuple items default / `undefined of unexisting keys`
// `List.isList(items)` means it got tuple items
List.isList(items) || type === 'array' ? List() :
type === 'string' ? '' :
type === 'null' ? null :
undefined
)
}
return ({
// todo: support `default` keyword
// https://github.com/ui-schema/ui-schema/issues/143
value: value,
internal: internal.update('internals', (internalInternals = List()) =>
internalInternals.push(Map())
),
...r,
}) as D
}
case 'list-item-delete':
return ({value = List(), internal = Map(), ...r}) => ({
value: value.splice(action.index, 1),
internal: internal.update('internals', (internalInternals = List()) =>
internalInternals.splice(action.index, 1)
),
...r,
}) as D
case 'list-item-move':
return ({value = List(), internal = Map(), ...r}) => ({
value: moveItem(value, action.fromIndex, action.toIndex),
internal: internal.update('internals', (internalInternals = List()) =>
moveItem(
(internalInternals.size - 1) < action.toIndex ?
// "set undefined at target":
// - to fix "Cannot update within non-data-structure value in path ["values","options",0,"choices",0]: undefined"
// - e.g. when rendering DND with existing data where not every item uses `internals`,
// the structures like [data1, data2] vs [internal1] can not be moved with splice
internalInternals.set(action.toIndex, undefined) :
(internalInternals.size - 1) < action.fromIndex ?
// "set undefined at target":
// - to fix similar issue, but now when "switching" between two, where the from ist after already existing internals
internalInternals.set(action.fromIndex, undefined) :
internalInternals,
action.fromIndex, action.toIndex
)
),
...r,
}) as D
case 'set':
return action.data as D
case 'update':
return action.updater as UIStoreUpdaterFn<D>
default:
// @ts-ignore
throw new Error('store updater for type not found: ' + action.type)
}
}