@xailabs/altx
Version:
Flux flavor based on alt.js
1,145 lines (1,144 loc) • 760 kB
JSON
{
"type": "File",
"start": 0,
"end": 8078,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 223,
"column": 0
}
},
"program": {
"type": "Program",
"start": 0,
"end": 8078,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 223,
"column": 0
}
},
"sourceType": "module",
"body": [
{
"type": "ImportDeclaration",
"start": 0,
"end": 60,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 60
}
},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"start": 7,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 22
}
},
"local": {
"type": "Identifier",
"start": 7,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 22
},
"identifierName": "connectToStores"
},
"name": "connectToStores"
}
}
],
"source": {
"type": "StringLiteral",
"start": 28,
"end": 59,
"loc": {
"start": {
"line": 1,
"column": 28
},
"end": {
"line": 1,
"column": 59
}
},
"extra": {
"rawValue": "alt-utils/lib/connectToStores",
"raw": "'alt-utils/lib/connectToStores'"
},
"value": "alt-utils/lib/connectToStores"
}
},
{
"type": "ImportDeclaration",
"start": 62,
"end": 107,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 45
}
},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"start": 69,
"end": 74,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 12
}
},
"local": {
"type": "Identifier",
"start": 69,
"end": 74,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 12
},
"identifierName": "React"
},
"name": "React"
}
},
{
"type": "ImportSpecifier",
"start": 78,
"end": 91,
"loc": {
"start": {
"line": 2,
"column": 16
},
"end": {
"line": 2,
"column": 29
}
},
"imported": {
"type": "Identifier",
"start": 78,
"end": 91,
"loc": {
"start": {
"line": 2,
"column": 16
},
"end": {
"line": 2,
"column": 29
},
"identifierName": "createElement"
},
"name": "createElement"
},
"local": {
"type": "Identifier",
"start": 78,
"end": 91,
"loc": {
"start": {
"line": 2,
"column": 16
},
"end": {
"line": 2,
"column": 29
},
"identifierName": "createElement"
},
"name": "createElement"
}
}
],
"source": {
"type": "StringLiteral",
"start": 99,
"end": 106,
"loc": {
"start": {
"line": 2,
"column": 37
},
"end": {
"line": 2,
"column": 44
}
},
"extra": {
"rawValue": "react",
"raw": "'react'"
},
"value": "react"
},
"trailingComments": [
{
"type": "CommentLine",
"value": " TODO: deprecate connectAlternative asap!",
"start": 111,
"end": 154,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 43
}
}
},
{
"type": "CommentBlock",
"value": " eslint-disable ",
"start": 160,
"end": 180,
"loc": {
"start": {
"line": 7,
"column": 0
},
"end": {
"line": 7,
"column": 20
}
}
},
{
"type": "CommentBlock",
"value": "*\r\n * A component decorator for connecting to immutable stores.\r\n *\r\n * Basically a wrapper around `alt/utils/connectToStores`. \r\n * Adds the necessary static methods `getStores()` and `getPropsFromStores()` to the decorated component.\r\n *\r\n * - Supports multiple stores.\r\n * - Supports a simplified, string-based access to stores, with optional renaming of props.\r\n * - Supports more flexible, redux-like access to stores using mapper functions.\r\n *\r\n * ### String notation\r\n *\r\n * @example\r\n * @connect([{store: MyStore, props: ['myValue', 'anotherValue']}])\r\n * export default class MyComponent extends React.Component {\r\n * render() {\r\n * const {myValue, anotherValue} = this.props;\r\n * ...\r\n * }\r\n * }\r\n *\r\n * You can rename props using the ` as ` alias syntax\r\n *\r\n * @example\r\n * @connect([{\r\n * store: PeopleStore,\r\n * props: ['items as people']\r\n * }, {\r\n * store: ProductStore,\r\n * props: ['items as products']\r\n * }])\r\n * export default class MyComponent extends React.Component {\r\n * render() {\r\n * // this.props.people, this.props.products, ...\r\n * }\r\n * }\r\n *\r\n * ### Function notation\r\n *\r\n * Use mapper functions instead of strings in order to manually retrieve store values.\r\n * The function receives the store state and the component props.\r\n *\r\n * @example\r\n * @connect([{\r\n * store: MyStore,\r\n * props: (state, props) => {\r\n * return {\r\n * item: state.get('items').filter(item => item.get('id') === props.id)\r\n * }\r\n * }\r\n * }])\r\n * export default class MyComponent extends React.Component {\r\n * render() {\r\n * const item = this.props.item;\r\n * }\r\n * }\r\n *\r\n * Technically, you could also mix all access methods, but this defeats the purpose of simple access:\r\n *\r\n * @example\r\n * @connect([{\r\n * store: MyStore,\r\n * props: ['someProp', 'anotherProp', (state, props) => {\r\n * return {\r\n * item: state.get('items').filter(item => item.get('id') === props.id)\r\n * }\r\n * }, 'some.nested.value as foo']\r\n * }])\r\n * export default class MyComponent extends React.Component {\r\n * ...\r\n * }\r\n *\r\n * There are however valid usecase for mixing access methods. For example, you might have keys that themselves contain dots.\r\n * For example, that is the case when using `validate.js` with nested constraints and keeping validation results in the store.\r\n * There might be an `errors` map in your storewith keys like `user.address.street`. In such a case you wouldn't be able to access those values because the dots do not\r\n * represent the actual keyPath in the tree:\r\n *\r\n * @example\r\n * @connect([{\r\n * store,\r\n * props: ['user.address.street', (state) => ({errors: state.getIn(['errors', 'user.address.street'])})]\r\n * }])\r\n *\r\n * @see https://github.com/goatslacker/alt/blob/master/docs/utils/immutable.md\r\n * @see https://github.com/goatslacker/alt/blob/master/src/utils/connectToStores.js\r\n *\r\n * @param {Array<{store: AltStore, props: Array<string>}>} definitions - A list of objects that each define a store connection\r\n ",
"start": 182,
"end": 3312,
"loc": {
"start": {
"line": 8,
"column": 0
},
"end": {
"line": 95,
"column": 3
}
}
},
{
"type": "CommentBlock",
"value": " eslint-enable ",
"start": 3314,
"end": 3333,
"loc": {
"start": {
"line": 96,
"column": 0
},
"end": {
"line": 96,
"column": 19
}
}
}
]
},
{
"type": "ExportDefaultDeclaration",
"start": 3335,
"end": 4303,
"loc": {
"start": {
"line": 97,
"column": 0
},
"end": {
"line": 116,
"column": 1
}
},
"declaration": {
"type": "FunctionDeclaration",
"start": 3350,
"end": 4303,
"loc": {
"start": {
"line": 97,
"column": 15
},
"end": {
"line": 116,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 3359,
"end": 3366,
"loc": {
"start": {
"line": 97,
"column": 24
},
"end": {
"line": 97,
"column": 31
},
"identifierName": "connect"
},
"name": "connect",
"leadingComments": null
},
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 3367,
"end": 3378,
"loc": {
"start": {
"line": 97,
"column": 32
},
"end": {
"line": 97,
"column": 43
},
"identifierName": "definitions"
},
"name": "definitions"
}
],
"body": {
"type": "BlockStatement",
"start": 3380,
"end": 4303,
"loc": {
"start": {
"line": 97,
"column": 45
},
"end": {
"line": 116,
"column": 1
}
},
"body": [
{
"type": "ReturnStatement",
"start": 3387,
"end": 4300,
"loc": {
"start": {
"line": 98,
"column": 4
},
"end": {
"line": 115,
"column": 6
}
},
"argument": {
"type": "FunctionExpression",
"start": 3394,
"end": 4299,
"loc": {
"start": {
"line": 98,
"column": 11
},
"end": {
"line": 115,
"column": 5
}
},
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 3403,
"end": 3414,
"loc": {
"start": {
"line": 98,
"column": 20
},
"end": {
"line": 98,
"column": 31
},
"identifierName": "targetClass"
},
"name": "targetClass"
}
],
"body": {
"type": "BlockStatement",
"start": 3416,
"end": 4299,
"loc": {
"start": {
"line": 98,
"column": 33
},
"end": {
"line": 115,
"column": 5
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 3427,
"end": 3532,
"loc": {
"start": {
"line": 99,
"column": 8
},
"end": {
"line": 101,
"column": 10
}
},
"expression": {
"type": "AssignmentExpression",
"start": 3427,
"end": 3531,
"loc": {
"start": {
"line": 99,
"column": 8
},
"end": {
"line": 101,
"column": 9
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 3427,
"end": 3448,
"loc": {
"start": {
"line": 99,
"column": 8
},
"end": {
"line": 99,
"column": 29
}
},
"object": {
"type": "Identifier",
"start": 3427,
"end": 3438,
"loc": {
"start": {
"line": 99,
"column": 8
},
"end": {
"line": 99,
"column": 19
},
"identifierName": "targetClass"
},
"name": "targetClass"
},
"property": {
"type": "Identifier",
"start": 3439,
"end": 3448,
"loc": {
"start": {
"line": 99,
"column": 20
},
"end": {
"line": 99,
"column": 29
},
"identifierName": "getStores"
},
"name": "getStores"
},
"computed": false
},
"right": {
"type": "FunctionExpression",
"start": 3451,
"end": 3531,
"loc": {
"start": {
"line": 99,
"column": 32
},
"end": {
"line": 101,
"column": 9
}
},
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 3462,
"end": 3531,
"loc": {
"start": {
"line": 99,
"column": 43
},
"end": {
"line": 101,
"column": 9
}
},
"body": [
{
"type": "ReturnStatement",
"start": 3477,
"end": 3520,
"loc": {
"start": {
"line": 100,
"column": 12
},
"end": {
"line": 100,
"column": 55
}
},
"argument": {
"type": "CallExpression",
"start": 3484,
"end": 3519,
"loc": {
"start": {
"line": 100,
"column": 19
},
"end": {
"line": 100,
"column": 54
}
},
"callee": {
"type": "MemberExpression",
"start": 3484,
"end": 3499,
"loc": {
"start": {
"line": 100,
"column": 19
},
"end": {
"line": 100,
"column": 34
}
},
"object": {
"type": "Identifier",
"start": 3484,
"end": 3495,
"loc": {
"start": {
"line": 100,
"column": 19
},
"end": {
"line": 100,
"column": 30
},
"identifierName": "definitions"
},
"name": "definitions"
},
"property": {
"type": "Identifier",
"start": 3496,
"end": 3499,
"loc": {
"start": {
"line": 100,
"column": 31
},
"end": {
"line": 100,
"column": 34
},
"identifierName": "map"
},
"name": "map"
},
"computed": false
},
"arguments": [
{
"type": "ArrowFunctionExpression",
"start": 3500,
"end": 3518,
"loc": {
"start": {
"line": 100,
"column": 35
},
"end": {
"line": 100,
"column": 53
}
},
"id": null,
"generator": false,
"expression": true,
"async": false,
"params": [
{
"type": "Identifier",
"start": 3501,
"end": 3504,
"loc": {
"start": {
"line": 100,
"column": 36
},
"end": {
"line": 100,
"column": 39
},
"identifierName": "def"
},
"name": "def"
}
],
"body": {
"type": "MemberExpression",
"start": 3509,
"end": 3518,
"loc": {
"start": {
"line": 100,
"column": 44
},
"end": {
"line": 100,
"column": 53
}
},
"object": {
"type": "Identifier",
"start": 3509,
"end": 3512,
"loc": {
"start": {
"line": 100,
"column": 44
},
"end": {
"line": 100,
"column": 47
},
"identifierName": "def"
},
"name": "def"
},
"property": {
"type": "Identifier",
"start": 3513,
"end": 3518,
"loc": {
"start": {
"line": 100,
"column": 48
},
"end": {
"line": 100,
"column": 53
},
"identifierName": "store"
},
"name": "store"
},
"computed": false
}
}
]
}
}
],
"directives": []
}
}
}
},
{
"type": "ExpressionStatement",
"start": 3542,
"end": 4246,
"loc": {
"start": {
"line": 102,
"column": 8
},
"end": {
"line": 113,
"column": 10
}
},
"expression": {
"type": "AssignmentExpression",
"start": 3542,
"end": 4245,
"loc": {
"start": {
"line": 102,
"column": 8
},
"end": {
"line": 113,
"column": 9
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 3542,
"end": 3572,
"loc": {
"start": {
"line": 102,
"column": 8
},
"end": {
"line": 102,
"column": 38
}
},
"object": {
"type": "Identifier",
"start": 3542,
"end": 3553,
"loc": {
"start": {
"line": 102,
"column": 8
},
"end": {
"line": 102,
"column": 19
},
"identifierName": "targetClass"
},
"name": "targetClass"
},
"property": {
"type": "Identifier",
"start": 3554,
"end": 3572,
"loc": {
"start": {
"line": 102,
"column": 20
},
"end": {
"line": 102,
"column": 38
},
"identifierName": "getPropsFromStores"
},
"name": "getPropsFromStores"
},
"computed": false
},
"right": {
"type": "FunctionExpression",
"start": 3575,
"end": 4245,
"loc": {
"start": {
"line": 102,
"column": 41
},
"end": {
"line": 113,
"column": 9
}
},
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 3584,
"end": 3598,
"loc": {
"start": {
"line": 102,
"column": 50
},
"end": {
"line": 102,
"column": 64
},
"identifierName": "componentProps"
},
"name": "componentProps"
}
],
"body": {
"type": "BlockStatement",
"start": 3600,
"end": 4245,
"loc": {
"start": {
"line": 102,
"column": 66
},
"end": {
"line": 113,
"column": 9
}
},
"body": [
{
"type": "ReturnStatement",
"start": 3615,
"end": 4234,
"loc": {
"start": {
"line": 103,
"column": 12
},
"end": {
"line": 112,
"column": 19
}
},
"argument": {
"type": "CallExpression",
"start": 3622,
"end": 4233,
"loc": {
"start": {
"line": 103,
"column": 19
},
"end": {
"line": 112,
"column": 18
}
},
"callee": {
"type": "MemberExpression",
"start": 3622,
"end": 3640,
"loc": {
"start": {
"line": 103,
"column": 19
},
"end": {
"line": 103,
"column": 37
}
},
"object": {
"type": "Identifier",
"start": 3622,
"end": 3633,
"loc": {
"start": {
"line": 103,
"column": 19
},
"end": {
"line": 103,
"column": 30
},
"identifierName": "definitions"
},
"name": "definitions"
},
"property": {
"type": "Identifier",
"start": 3634,
"end": 3640,
"loc": {
"start": {
"line": 103,
"column": 31
},
"end": {
"line": 103,
"column": 37
},
"identifierName": "reduce"
},
"name": "reduce"
},
"computed": false
},
"arguments": [
{
"type": "ArrowFunctionExpression",
"start": 3641,
"end": 4228,
"loc": {
"start": {
"line": 103,
"column": 38
},
"end": {
"line": 112,
"column": 13
}
},
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 3642,
"end": 3648,
"loc": {
"start": {
"line": 103,
"column": 39
},
"end": {
"line": 103,
"column": 45
},
"identifierName": "result"
},
"name": "result"
},
{
"type": "Identifier",
"start": 3650,
"end": 3653,
"loc": {
"start": {
"line": 103,
"column": 47
},
"end": {
"line": 103,
"column": 50
},
"identifierName": "def"
},
"name": "def"
}
],
"body": {
"type": "BlockStatement",
"start": 3658,
"end": 4228,
"loc": {
"start": {
"line": 103,
"column": 55
},
"end": {
"line": 112,
"column": 13
}
},
"body": [
{
"type": "IfStatement",
"start": 3677,
"end": 3920,
"loc": {
"start": {
"line": 104,
"column": 16
},
"end": {
"line": 107,
"column": 17
}
},
"test": {
"type": "BinaryExpression",
"start": 3681,
"end": 3712,
"loc": {
"start": {
"line": 104,
"column": 20
},
"end": {
"line": 104,
"column": 51
}
},
"left": {
"type": "UnaryExpression",
"start": 3681,
"end": 3697,
"loc": {
"start": {
"line": 104,
"column": 20
},
"end": {
"line": 104,
"column": 36
}
},
"operator": "typeof",
"prefix": true,
"argument": {
"type": "MemberExpression",
"start": 3688,
"end": 3697,
"loc": {
"start": {
"line": 104,
"column": 27
},
"end": {
"line": 104,
"column": 36
}
},
"object": {
"type": "Identifier",
"start": 3688,
"end": 3691,
"loc": {
"start": {
"line": 104,
"column": 27
},
"end": {
"line": 104,
"column": 30
},
"identifierName": "def"
},
"name": "def"
},
"property": {
"type": "Identifier",
"start": 3692,
"end": 3697,
"loc": {
"start": {
"line": 104,
"column": 31
},
"end": {
"line": 104,
"column": 36
},
"identifierName": "props"
},
"name": "props"
},
"computed": false
},
"extra": {
"parenthesizedArgument": false
}
},
"operator": "===",
"right": {
"type": "StringLiteral",
"start": 3702,
"end": 3712,
"loc": {
"start": {
"line": 104,
"column": 41
},
"end": {
"line": 104,
"column": 51
}
},
"extra": {
"rawValue": "function",
"raw": "'function'"
},
"value": "function"
}
},
"consequent": {
"type": "BlockStatement",
"start": 3714,
"end": 3920,
"loc": {
"start": {
"line": 104,
"column": 53
},
"end": {
"line": 107,
"column": 17
}
},
"body": [
{
"type": "ReturnStatement",
"start": 3828,
"end": 3901,
"loc": {
"start": {
"line": 106,
"column": 20
},