richarddobron/bigpipe
Composer 安装命令:
composer require richarddobron/bigpipe
包简介
BigPipe: Pipelining web pages for high performance built in PHP.
README 文档
README
This library currently implements small part of Facebook BigPipe so far, but the advantage is to efficiently insert/replace content and work with the DOM. It is also possible to easily call JavaScript modules from PHP.
👀 Demo App
Try the app with live demo or check how to install.
📕 Full documentation
https://richarddobron.github.io/bigpipe-php/
ℹ️ Requirements
- PHP 7.1 or higher
- Webpack
📦 Installation
Follow these steps to install and set up:
1. Install composer package:
$ composer require richarddobron/bigpipe
2. Install npm package:
$ npm install bigpipe-util
3. Add the following to /path/to/resources/js/app.js:
import Primer from 'bigpipe-util/src/Primer'; Primer(); window.require = (modulePath) => { return modulePath.startsWith('bigpipe-util/') ? require('bigpipe-util/' + modulePath.substring(13) + '.js').default : require('./' + modulePath).default; };
4. Add this line to the page footer:
<?= \dobron\BigPipe\BigPipe::render() ?>
🪄 DOMOPS API
- setContent: Sets the content of an element.
- appendContent: Insert content as the last child of specified element.
- prependContent: Insert content as the first child of specified element.
- insertAfter: Insert content after specified element.
- insertBefore: Insert content before specified element.
- remove: Remove specified element and its children.
- replace: Replace specified element with content.
- eval: Evaluates JavaScript code represented as a string.
$response = new \dobron\BigPipe\AsyncResponse(); $response->setContent('div#content', $newContent); $response->send();
🔄 Refresh & Redirecting
$response = new \dobron\BigPipe\AsyncResponse(); $response->reload(250); // reload page with 250ms delay // or $response->redirect('/onboarding', 500); // redirect with 500ms delay $response->send();
ℹ️ Payload
$response = new \dobron\BigPipe\AsyncResponse(); $response->setPayload([ 'username' => $_POST['username'], 'status' => 'unavailable', 'message' => 'Username is unavailable.', ]); $response->send();
🛠️ BigPipe API
- require: Call JavaScript module method. You can call a specific class method or a regular function with the custom arguments.
Example PHP code:
$asyncResponse = new \dobron\BigPipe\AsyncResponse(); $asyncResponse->bigPipe()->require("require('SecretModule').run()", [ 'first argument', 'second argument', ... ]); // is same as $asyncResponse->bigPipe()->require(["SecretModule", "run"], ...) // is same as $asyncResponse->bigPipe()->require()->SecretModule()->run(...) $asyncResponse->send();
Example JavaScript code:
class SecretModule { run(first, second) { // ... } }
- transport: Through transport markers you can send HTML content but also transform the content into JavaScript objects (such as Map, Set or Element).
Example PHP code:
$asyncResponse = new \dobron\BigPipe\AsyncResponse(); $asyncResponse->bigPipe()->require("require('Chart').setup()", [ 'element' => \dobron\BigPipe\TransportMarker::transportElement('chart-div'), 'dataPoints' => $asyncResponse->transport()->transportSet([ ['x' => 10, 'y' => 71], ['x' => 20, 'y' => 55], ['x' => 30, 'y' => 50], ['x' => 40, 'y' => 65], ]), ]); $asyncResponse->send();
⚡️ What all can be Ajaxifed?
🔗 Links
<a href="#" ajaxify="/ajax/remove.php" rel="async">Remove Item</a>
📝 Forms
<form action="/submit.php" method="POST" rel="async"> <input name="user"> <input type="submit" name="Done"> </form>
💬 Dialogs
<a href="#" ajaxify="/ajax/modal.php" rel="dialog">Open Modal</a>
🌟 Inspiration
BigPipe is inspired by Facebook's BigPipe. For more details read their blog post: Pipelining web pages for high performance.
💡 Motivation
There is a large number of PHP projects for which moving to modern frameworks like Laravel Livewire, React, Vue.js (and many more!) could be very challenging.
The purpose of this library is to rapidly reduce the continuously repetitive code to work with the DOM and improve the communication barrier between PHP and JavaScript.
📑 Version Guidance
| Version | Released | Status | Repo | PHP Version |
|---|---|---|---|---|
| 0.x | 2022-03-27 | Maintained | v0.x | >=7.1 |
| 1.x | 2022-07-29 | Latest | v1.x | ^8.0 |
🤝 Contributing
Please see CONTRIBUTING for details.
📜 License
This project is licensed under the MIT License. See the LICENSE file for details.
richarddobron/bigpipe 适用场景与选型建议
richarddobron/bigpipe 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.03k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2022 年 03 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「javascript」 「html」 「dom」 「async」 「xhr」 「bigpipe」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 richarddobron/bigpipe 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 richarddobron/bigpipe 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 richarddobron/bigpipe 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
Generates a Blade directive exporting all of your named Laravel routes. Also provides a nice route() helper function in JavaScript.
A library that provides basic utilities for creating HTML documents.
A bridge between SimpleXML and the DOM extension, plus a bunch of convenience methods
Caching and compression for Twig assets (JavaScript and CSS).
A pretty nice way to expose your translation messages to your JavaScript.
统计信息
- 总下载量: 17.03k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-03-27