daverandom / loopio
为使用 React 和 Alert 事件循环的组件提供互操作性
v0.1.0
2014-06-18 14:39 UTC
Requires
- php: >=5.4.0
- rdlowrey/alert: ~0.1
- react/react: ~0.1
This package is auto-updated.
Last update: 2024-08-25 07:25:49 UTC
README
这个库仅仅是一系列适配器,允许你使用围绕 React 事件循环设计的应用程序与 Alert 事件循环一起工作,反之亦然。它本身不提供任何完整的功能。
为 React 的所有稳定版本(至 0.4.x 系列)和 Alert 的所有稳定版本(至 0.8.x 系列)提供适配器,不包括初始的 Alert 版本(0.1.0)。
### 安装
首选通过 Composer。
"require": {
"daverandom/loopio": "~0.1.0"
}
### 使用
创建正确适配器的最佳方法是使用 Loopio\LoopFactory
的适当方法。这将自动检测 Alert 和 React 的安装版本,并返回适合您组合的正确适配器。
如果您使用 React 作为主要的事件循环,并且想在您的应用程序中使用围绕 Alert 设计的组件(如 Artax),可以这样创建适配器
<?php
// Create a React event loop
$reactLoop = React\EventLoop\Factory::create();
// Create an Alert adapter
$alertLoop = (new Loopio\LoopFactory)->createAlertLoop($reactLoop);
// Create an Artax async client
$client = new Artax\AsyncClient($alertLoop);
如果您使用 Alert 作为主要的事件循环,并且想在您的应用程序中使用围绕 React 设计的组件(如 Ratchet),可以这样创建适配器
<?php
// Create an Alert event loop
$alertLoop = (new Alert\ReactorFactory)->select();
// Create a React adapter
$reactLoop = (new Loopio\LoopFactory)->createReactLoop($alertLoop);
// Create a Ratchet app
$client = new Ratchet\App('localhost', 8080, '127.0.0.1', $reactLoop);