Skip to content

Instantly share code, notes, and snippets.

@neurosnap
Last active February 6, 2020 04:21
Show Gist options
  • Save neurosnap/0942c297f67b528e3f8a1913387b992e to your computer and use it in GitHub Desktop.
Save neurosnap/0942c297f67b528e3f8a1913387b992e to your computer and use it in GitHub Desktop.
new robodux api experiment
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: 'cool@runnings.com',
},
2: {
id: '2',
role: '3',
email: 'hilary@clinton.com'
}
},
roles: {
3: { id: '3', name: 'owner' },
},
roleUsers: { 3: ['1', '2'] },
emailUser: {
'cool@runnings.com': '1',
'hilary@clinton.com': '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