Function
Static Public Summary | ||
public |
attributeObjectToHtml(attributes: {}): string Takes an object that maps attribute names to values, and returns it as html formatted attributes. |
|
public |
Element.remove() polyfill for IE11 compatibility |
|
public |
ensureMapHasDataInReduxStore(typeMap: *, dispatchAction: *, dispatch: *): boolean Used to ensure that a map built by makeTypeMappedReduxMapFromApiData or makeImmutableOrderedMapFromValueArray is loaded in redux-store |
|
public |
escapeAttributeValue(value: *): string Escape HTML attribute value. |
|
public |
getFileExtension(filename: *): string Get file extension. |
|
public |
getObjectFromReduxMapOrNullIfLoading(map: *, id: *, dispatchAction: *, dispatch: *): null | Immutable.Map Simple util to fetch data from a redux-api-map (which should always be built by makeApiDataMapIsLoading, makeApiDataMapNewData or makeApiDataMapError). |
|
public |
getValuesFromTypeMappedReduxMap(typeMappedReduxMap: *, typeKey: *, fallbackToDefault: *): Immutable.OrderedMap<string, Immutable.Map<string, string>> Used to fetch the ImmutableOrderedMap of values for a <typeKey> in a structure built by makeTypeMappedReduxMapFromApiData. |
|
public |
isInlineTag(tagName: string): * Returns |
|
public |
isSelfClosingTag(tagName: string): * Returns |
|
public |
makeApiDataMapDeleted(oldData: *): Immutable.Map Used to mark an object in redux-state as deleted. |
|
public |
makeApiDataMapError(error: *): Immutable.Map Util used by all |
|
public |
makeApiDataMapIsLoading(oldApiDataMap: *): Immutable.Map<string, any> Util used by all |
|
public |
makeApiDataMapNewData(newData: *, fromList: *, noWrap: *): Immutable.Map Util used by all |
|
public |
makeCustomError(name: string, extendsError: Error): Error Make a custom error "class". |
|
public |
makeHtmlEndTag(tagName: string): string Make a HTML end tag. |
|
public |
makeHtmlStartTag(tagName: string, attributes: {}): string Make a HTML start tag. |
|
public |
makeImmutableOrderedMapFromValueArray(valueArray: *, valueKey: *): Immutable.OrderedMap<string, Immutable.Map<string, string>> Used for the internal OrderedMap from makeTypeMappedReduxMapFromApiData, and should be used for other type-lists from api. |
|
public |
makeTypeMappedReduxMapFromApiData(apiResponseBodydata: *): Immutable.Map<string, Immutable.OrderedMap<string, Immutable.Map<string, string>>> Used for apis like nodePaymentSubscriptionTypes and nodeMembershipTypes. |
|
public |
onDocumentReady(callback: *) Wrap a callback that is called when the document is done loading. |
|
public |
typeDetect(obj: *): string Detect the type of an object and return the result as a string. |
Static Public
public attributeObjectToHtml(attributes: {}): string source
import {attributeObjectToHtml} from 'ievv_jsbase/lib/html/utils'
Takes an object that maps attribute names to values, and returns it as html formatted attributes.
The result will start with an empty space if the provided object is not empty.
Params:
Name | Type | Attribute | Description |
attributes | {} | Object mapping attribute names to values. |
public elementRemovePolyfill() source
import elementRemovePolyfill from 'ievv_jsbase/lib/polyfill/elementRemovePolyfill'
Element.remove() polyfill for IE11 compatibility
public ensureMapHasDataInReduxStore(typeMap: *, dispatchAction: *, dispatch: *): boolean source
import {ensureMapHasDataInReduxStore} from 'ievv_jsbase/lib/utils/reduxApiUtilities'
Used to ensure that a map built by makeTypeMappedReduxMapFromApiData or makeImmutableOrderedMapFromValueArray is loaded in redux-store
Note that this should only be used in cases where the data is static (e.g. load once, use always), as it does not pass any params to the api or check if any specific data is present. This simply triggers the given action if the map is empty and not already loading.
Params:
Name | Type | Attribute | Description |
typeMap | * | The redux-store-map you want to ensure is loaded (e.g. userNotificationTypesMap) |
|
dispatchAction | * | the redux-action to dispatch to load the typemap |
|
dispatch | * | The dispatcher to use to dispatch the dispatchAction, e.g. props.dispatch |
public escapeAttributeValue(value: *): string source
import {escapeAttributeValue} from 'ievv_jsbase/lib/html/utils'
Escape HTML attribute value.
Params:
Name | Type | Attribute | Description |
value | * | The attribute value to escape. Coerced to string if it not a string. |
public getFileExtension(filename: *): string source
import {getFileExtension} from 'ievv_jsbase/lib/utils/filepath'
Get file extension.
Params:
Name | Type | Attribute | Description |
filename | * | A filename. An URL also works. |
public getObjectFromReduxMapOrNullIfLoading(map: *, id: *, dispatchAction: *, dispatch: *): null | Immutable.Map source
import {getObjectFromReduxMapOrNullIfLoading} from 'ievv_jsbase/lib/utils/reduxApiUtilities'
Simple util to fetch data from a redux-api-map (which should always be built by makeApiDataMapIsLoading, makeApiDataMapNewData or makeApiDataMapError).
This util will lookup the given id in the given map and return it if it exists.
If the entry is missing or loading, null is returned.
If the entry is missing (and not already loading), the given dispatchAction
is dispatched and null is returned.
Note that this util will still return the object even if it is an error-object (apiError !== null
), so you need
to handle errors in your component.
Params:
Name | Type | Attribute | Description |
map | * | {Immutable.Map} a map built by makeApiDataMapIsLoading, makeApiDataMapNewData or makeApiDataMapError |
|
id | * | {number} the entry-id to look for in the map |
|
dispatchAction | * | {function} the |
|
dispatch | * | {function} a |
Return:
null | Immutable.Map | null if the entry is loading, or an ImmutableMap of the entry if it exists. |
public getValuesFromTypeMappedReduxMap(typeMappedReduxMap: *, typeKey: *, fallbackToDefault: *): Immutable.OrderedMap<string, Immutable.Map<string, string>> source
import {getValuesFromTypeMappedReduxMap} from 'ievv_jsbase/lib/utils/reduxApiUtilities'
Used to fetch the ImmutableOrderedMap of values for a <typeKey> in a structure built by makeTypeMappedReduxMapFromApiData. See its documentation for structure.
If the given <typeKey> is not present in the map, then the entry referenced by TYPE_MAPPED_REDUX_MAP_DEFAULT_KEY will be returned instead.
Params:
Name | Type | Attribute | Description |
typeMappedReduxMap | * | a map built by makeTypeMappedReduxMapFromApiData |
|
typeKey | * | the <typeKey> to look for in the map |
|
fallbackToDefault | * | if true return default-data if no data for typekey is present. If false, return null. |
public isInlineTag(tagName: string): * source
import {isInlineTag} from 'ievv_jsbase/lib/html/utils'
Returns True
if the provided tagName
is an inline tag.
Params:
Name | Type | Attribute | Description |
tagName | string | The tag name. |
Return:
* |
public isSelfClosingTag(tagName: string): * source
import {isSelfClosingTag} from 'ievv_jsbase/lib/html/utils'
Returns True
if the provided tagName
is a self closing tag.
Params:
Name | Type | Attribute | Description |
tagName | string | The tag name. |
Return:
* |
public makeApiDataMapDeleted(oldData: *): Immutable.Map source
import {makeApiDataMapDeleted} from 'ievv_jsbase/lib/utils/reduxApiUtilities'
Used to mark an object in redux-state as deleted.
Params:
Name | Type | Attribute | Description |
oldData | * |
Return:
Immutable.Map |
public makeApiDataMapError(error: *): Immutable.Map source
import {makeApiDataMapError} from 'ievv_jsbase/lib/utils/reduxApiUtilities'
Util used by all action.js
-files in redux/api/*
.
This is used to build a common error-format for all redux-map-entries.
sets isLoading
to false
, data
to null
, timestamp
to now.
stores the error in the field apiError
formatted like this:
apiError: ImmutableMap({ status: error.response.status, bodydata: ImmutableMap(error.response.bodydata) })
Params:
Name | Type | Attribute | Description |
error | * |
Return:
Immutable.Map |
public makeApiDataMapIsLoading(oldApiDataMap: *): Immutable.Map<string, any> source
import {makeApiDataMapIsLoading} from 'ievv_jsbase/lib/utils/reduxApiUtilities'
Util used by all action.js
-files in redux/api/*
.
This is used to mark an entry in a redux-map as loading.
sets isLoading
to true
and apiError
to null.
Params:
Name | Type | Attribute | Description |
oldApiDataMap | * | Previous contents of |
public makeApiDataMapNewData(newData: *, fromList: *, noWrap: *): Immutable.Map source
import {makeApiDataMapNewData} from 'ievv_jsbase/lib/utils/reduxApiUtilities'
Util used by all action.js
-files in redux/api/*
.
This is used to format data to store in redux-state-map when an api-call is successful.
The given newData
is inserted as an ImmutableMap data
.
sets isLoading
to false
, apiError
to null and timestamp
to now.
Params:
Name | Type | Attribute | Description |
newData | * | {Object} the object returned from the api which should be formated for insertion in the redux-state-map. If fromList is true this should be an iterable. |
|
fromList | * | {boolean} if true, make an ImmutableList of the given data instead of ImmutableMap |
|
noWrap | * | {boolean} if true, newData will not be wrapped in ImmutableMap or ImmutableList. Only use this if the data you are setting is already an ImmutableMap or ImmutableList! |
Return:
Immutable.Map | newly formatted ImmutableMap ready to be placed in redux-state-map |
public makeCustomError(name: string, extendsError: Error): Error source
import makeCustomError from 'ievv_jsbase/lib/makeCustomError'
Make a custom error "class".
Makes an old style prototype based error class.
Example:
// In myerrors.js
export let MyCustomError = makeCustomError('MyCustomError');
// Using the error
import {MyCustomError} from './myerrors';
throw new MyCustomError('The message');
try {
throw new MyCustomError('The message', {
code: 'stuff_happened',
details: {
size: 10
}
});
} catch(e) {
if(e instanceof MyCustomError) {
console.error(`${e.toString()} -- Code: ${e.code}. Size: ${e.details.size}`);
}
}
let NotFoundError = makeCustomError('NotFoundError');
// error instanceof NotFoundError === true
// error instanceof Error === true
let MyValueError = makeCustomError('MyValueError', TypeError);
let error = new MyValueError();
// error instanceof MyValueError === true
// error instanceof TypeError === true
// error instanceof Error === true
let MySuperError = makeCustomError('MySuperError', TypeError);
let MySubError = makeCustomError('MySubError', MySuperError);
let error = new MySubError();
// error instanceof MySubError === true
// error instanceof MySuperError === true
// error instanceof TypeError === true
// error instanceof Error === true
public makeHtmlEndTag(tagName: string): string source
import {makeHtmlEndTag} from 'ievv_jsbase/lib/html/utils'
Make a HTML end tag.
Handles self-closing tags automatically.
Params:
Name | Type | Attribute | Description |
tagName | string | Tag name. |
public makeHtmlStartTag(tagName: string, attributes: {}): string source
import {makeHtmlStartTag} from 'ievv_jsbase/lib/html/utils'
Make a HTML start tag.
Handles self-closing tags automatically.
Params:
Name | Type | Attribute | Description |
tagName | string | Tag name. |
|
attributes | {} | Object mapping attribute names to values. |
public makeImmutableOrderedMapFromValueArray(valueArray: *, valueKey: *): Immutable.OrderedMap<string, Immutable.Map<string, string>> source
import {makeImmutableOrderedMapFromValueArray} from 'ievv_jsbase/lib/utils/reduxApiUtilities'
Used for the internal OrderedMap from makeTypeMappedReduxMapFromApiData, and should be used for other type-lists from api.
The only required fieldname on the api-data is value
, which will be used as key in the ImmutableOrderedMap
Builds a structure like this: ImmutableOrderedMap({ <valueKey>: ImmutableMap({ label: <some label>, description: <some description>, <otherfield>: <otherfieldkey>, ... }) })
from input-data formatted like this: [ { "value": "<valueKey>", "label": "<some label>", "description": "<some description>", <otherfield>: <otherfieldkey>, ... } ]
Params:
Name | Type | Attribute | Description |
valueArray | * | See input-data doc above |
|
valueKey | * | default to 'value' as in example above. can be set to any valid value. note that this is NOT validated or enforced in any way |
public makeTypeMappedReduxMapFromApiData(apiResponseBodydata: *): Immutable.Map<string, Immutable.OrderedMap<string, Immutable.Map<string, string>>> source
import {makeTypeMappedReduxMapFromApiData} from 'ievv_jsbase/lib/utils/reduxApiUtilities'
Used for apis like nodePaymentSubscriptionTypes and nodeMembershipTypes.
Builds a structure like this: ImmutableMap({ <nodeType>: ImmutableOrderedMap({ <valueKey>: ImmutableMap({ label: <some label>, description: <some description>, <otherfield>: <otherfieldkey>, ... }) }) })
Expects apiResponseBodydata to be formatted like this: { "<nodeType>": [ { "value": "<valueKey>", "label": "<some label>", "description": "<some description>", <otherfield>: <otherfieldkey>, ... } ] }
Params:
Name | Type | Attribute | Description |
apiResponseBodydata | * |
|
public onDocumentReady(callback: *) source
import onDocumentReady from 'ievv_jsbase/lib/utils/onDocumentReady'
Wrap a callback that is called when the document is done loading.
Params:
Name | Type | Attribute | Description |
callback | * | A callback function. Called without any arguments. |
public typeDetect(obj: *): string source
import typeDetect from 'ievv_jsbase/lib/utils/typeDetect'
Detect the type of an object and return the result as a string.
Handles the following types:
- null (returned as
"null"
). - undefined (returned as
"undefined"
). - Number (returned as
"number"
). - Boolean (returned as
"boolean"
). - String (returned as
"string"
). - Array (returned as
"array"
). - Map (returned as
"map"
). - Set (returned as
"set"
). - Function (returned as
"function"
). - Object (returned as
"object"
).
We do not handle classes - they are returned as "function"
.
We could handle classes, but for Babel classes that will require
a fairly expensive and error prone regex.
Params:
Name | Type | Attribute | Description |
obj | * | An object to detect the type for. |