@aardito2/realm 中文文档教程

发布于 8年前 浏览 26 项目主页 更新于 3年前

realm

Realm 是使用 Elm 的 Redux 的替代实现。 操作是在带有有效负载的 JavaScript 中创建的,该有效负载通过端口发送到您的 Elm 存储中。 Elm 在 Redux 中扮演 reducer 的角色,并将新状态发送回 JavaScript。

Usage

JavaScript

npm install @aardito2/realm

createStore(elmStore, initialState = {}, enhancer)

// using elm-webpack-loader
import elmStore from './store.elm';

const initialState = {};
const store = createStore(elmStore.Store, initialState);

applyMiddleware

请参阅 Redux 文档

createAction(actionType) => payload => action

const INCREMENT = 'increment';
const increment = createAction(INCREMENT);

const SET_STRING = 'set_string';
const setString = createAction(SET_STRING);

store.dispatch(action)

dispatch(increment());
dispatch(setString('foo'));

Elm

elm-package install @aardito2/realm

您的 Elm 文件应该是 Platform.programWithFlags。 总的来说,您的更新应该使用 Realm.updateState,它接受一个传出端口和一个更新函数并返回一个新的更新函数,该函数会自动将您的更新状态发送回 JavaScript。

您的传出端口将具有签名 model -> 命令消息此端口必须命名为 nextState!

对于 JavaScript 中使用的每个操作,需要两件事:

1) 一个与操作类型同名的传入端口。

2) 订阅上述端口,将传入的操作转换为 Msg 以供您的更新功能处理。

有关 Elm 中存储结构的完整示例,请参阅 store.elm

realm

Realm is an alternate implementation of Redux using Elm. Actions are created in JavaScript with a payload, which is sent through ports into your Elm store. Elm performs the role of a reducer in Redux, and sends the new state back to JavaScript.

Usage

JavaScript

npm install @aardito2/realm

createStore(elmStore, initialState = {}, enhancer)

// using elm-webpack-loader
import elmStore from './store.elm';

const initialState = {};
const store = createStore(elmStore.Store, initialState);

applyMiddleware

See Redux docs.

createAction(actionType) => payload => action

const INCREMENT = 'increment';
const increment = createAction(INCREMENT);

const SET_STRING = 'set_string';
const setString = createAction(SET_STRING);

store.dispatch(action)

dispatch(increment());
dispatch(setString('foo'));

Elm

elm-package install @aardito2/realm

Your Elm file should be a Platform.programWithFlags. In main, your update should use Realm.updateState, which takes an outgoing port and an update function and returns a new update function which will automatically send your updated state back to JavaScript.

Your outgoing port will have the signature model -> Cmd msg. This port must be named nextState!

For each action used in JavaScript, two things are required:

1) An incoming port with the same name as the action type.

2) A subscription to the above port which converts the incoming action into a Msg to be handled by your update function.

See store.elm for a full example of the structure of the store in Elm.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文