Last active
February 6, 2020 04:21
-
-
Save neurosnap/0942c297f67b528e3f8a1913387b992e to your computer and use it in GitHub Desktop.
new robodux api experiment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import createTable from './slice-map'; | |
import createIndexMany from './create-index'; | |
import createPrimitive from './slice-assign'; | |
import createLoaderTable from './slice-loading-map'; | |
const createIndex = (p: any) => createTable<{ [key: string]: string }>(p); | |
interface User { | |
id: string; | |
email: string; | |
role: string; | |
} | |
interface Users { | |
[key: string]: User; | |
} | |
interface Role { | |
id: string; | |
name: string; | |
} | |
interface Roles { | |
[key: string]: Role; | |
} | |
// mapSlice | |
const users = createTable<Users>({ name: 'users' }); | |
const roles = createTable<Roles>({ name: 'roles' }); | |
// mapSlice | |
const emailUser = createIndex({ name: 'emailUser' }); | |
// listMapSlice | |
const roleUsers = createIndexMany({ name: 'roleUsers' }); | |
// assignSlice | |
const token = createPrimitive({ name: 'token', initialState: '' }); | |
// loaderMapSlice | |
const loader = createLoaderTable({ name: 'loader' }); | |
/* | |
{ | |
users: { | |
1: { | |
id: '1', | |
role: '3', | |
email: '[email protected]', | |
}, | |
2: { | |
id: '2', | |
role: '3', | |
email: '[email protected]' | |
} | |
}, | |
roles: { | |
3: { id: '3', name: 'owner' }, | |
}, | |
roleUsers: { 3: ['1', '2'] }, | |
emailUser: { | |
'[email protected]': '1', | |
'[email protected]': '2', | |
}, | |
token: '123', | |
loader: { | |
users: { | |
loading: false, | |
success: false, | |
error: '', | |
message: '', | |
}, | |
roles: { | |
loading: false, | |
success: false, | |
error: '', | |
message: '', | |
}, | |
}, | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment