8000 GitHub - richardDobron/bigpipe-util: This library currently implements small part of Facebook BigPipe concept 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.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

This library currently implements small part of Facebook BigPipe concept 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.

License

Notifications You must be signed in to change notification settings

richardDobron/bigpipe-util

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BigPipe logo

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.

📕 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 these lines to the page footer:

<script>
    (new (require("bigpipe-util/ServerJS"))).handle(<?=json_encode(\dobron\BigPipe\BigPipe::jsmods())?>);
</script>

Request API

import AsyncRequest from 'bigpipe-util/src/AsyncRequest';

const request = (new AsyncRequest('/ajax/remove.php'))
  // or .setURI('/ajax/remove.php')
  .setMethod('POST')
  .setData({
    param: 'value',
  })
  .setInitialHandler(() => {
      // pre-request callback function
  })
  .setHandler((jsonResponse) => {
      // A function to be called if the request succeeds
  })
  .setErrorHandler((xhr) => {
      // A function to be called if the request fails
  })
  .setFinallyHandler((xhr) => {
      // after request callback function
  })
  .send();

if (OH_NOES_WE_NEED_TO_CANCEL_RIGHT_NOW_OR_ELSE) {
  request.abort();
}

⚡️ 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.

🤝 Contributing

We welcome contributions! If you'd like to help improve this project, feel free to open an issue or submit a pull request.

📜 License

The MIT License (MIT). Please see License File for more information.

About

This library currently implements small part of Facebook BigPipe concept 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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published
0