0.1.2 • Published 6 years ago

@methodexists/me-core v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

me-core

Core functionality for MethodExists apps.

Usage

Init core module

core.init({
  apiService: APIService, // api service module with REST methods
  getLocale: () => app._store.getState().app.locale, // getter of the current app locale (for error messages i18n)
});

apiService is required for me-core functioning. getLocale is optional. 'en-US' locale is used by default.

Register formulas in records model

import recordsModel, { init as recordsModelInit } from '~/models/records';

app.model(recordsModel);
recordsModelInit({
  formulas: {
    users: record => ({
      ...record,
      generatedByFormula: Math.random(),
    }),
  },
});

Provide options into notifications model

import notificationsModel, { init as notificationsModelInit } from '~/models/notifications';
import icon from '~/assets/images/icon.png';
import { profileUsernameSelector } from '~/selectors';

app.model(notificationsModel);
notificationsModelInit({
  icon,
  profileUsernameSelector,
});

Examples

ListProvider passing props:

<ListProvider namespace="users" table="users" primaryKey="username">
  {({ list, isLoading } => (
    isLoading ? <div>Loading...</div> : <div>{ list.map(renderListItem) }</div>
  )}
</ListProvider>

API

<ListProvider /> component

import { ListProvider } from 'me-core';
PropTypeDefaultDescription
* namespacestring
* tablestring
* childrenelement or funcIf children is func then ListProvider will pass { isLoading, list, total, schema } as arguments
filtersobject{}
esQueryobjectundefined
sortobject{ 'name.raw': 'asc' }
limitnumber20
primaryKeystring'id'
sourceobject

<RecordProvider /> component

import { RecordProvider } from 'me-core';
PropTypeDefaultDescription
* namespacestring
* tablestring
* childrenelement or funcIf children is func then RecordProvider will pass { isLoading, record, schema } as arguments
primaryKeystring'id'
idstring

<AuditLogProvider /> component

import { AuditLogProvider } from 'me-core';
PropTypeDescription
* namespacestring
* tablestring
* childrenelement or funcIf children is func then provider will pass { isLoading, log, schema } as argument
* idstring

Selectors

recordHasUnsavedChangesSelector

Compares metafields lastSynced and lastChanged to figure out if the record was changed and not saved. lastSynced field updated on any Save/Fetch operation (setRecord action). lastChanged field updated on any Update operation (update action).

Models

lists

Lists model works with /table API by default. If the tableName is users it calls /user API. To use /dynamo API you need to set params.useDynamo = true.

Contributing

See CONTRIBUTING.md for how to develop a component.

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.28

6 years ago

0.0.27

6 years ago

0.0.24

6 years ago

0.0.21

6 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.14

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago