0.2.0 • Published 1 year ago

@acanto/core-orchestrations v0.2.0

Weekly downloads
31
License
ISC
Repository
gitlab
Last release
1 year ago

Frontend

Orchestrations

Abstraction of kind of complex but common UI patterns.

Other examples and patterns of complex implementations

Retrieval of a rendered component via ajax

This is a bare minimal example. Let's say that you need to add this ajax powered component to the home page. The homepage template home/index.twig needs an element to hold the async content:

<div id="my-async-content">Loading...</div>

Then follow these steps:

    1. run acanto component my-component. In the generated component template frontend/components/MyComponent/index.twig you can put what you want, to pass data from the db see next step.
    1. got to plugins/acanto/routes.php and add:
Route::get('/ajax/my-data', function () {
  // static data from backend
  $json = ['id' => 'ciao', 'whatever' => 'dynamic-data'];
  // or dynamic data from models
  $slug = strtolower(@$_GET['slug']);
  $json = Acanto\Acanto\Models\Something::where('slug', $slug)->first();

  return Acanto\Data\Plugin::getAjaxFragment(
    'MyComponent',
    ['dataToUse' => $json],
    'home'
  );
});
    1. got to frontend/routes/home.js and add:
import { $ } from "@acanto/frontend/dom";
import ajax from "@acanto/frontend/ajax";
import { buildQueryString } from "@acanto/frontend/helpers"; // if needed
import Lazy from "@acanto/frontend/lazy"; // if needed

const CLASS_LOADING = "is-loading";
const $results = $("#my-async-content");

function fetchContent(data) {
  const queryString = data ? buildQueryString(data) : "";
  $results.classList.add(CLASS_LOADING);

  ajax(`/ajax/my-data${queryString}`).then(({ data }) => {
    $resultsAsync.innerHTML = data;
    $results.classList.remove(CLASS_LOADING);
    new Lazy({ container: $results });
  });
}

fetchContent({ slug: "some-unique-slug" });
0.2.0

1 year ago

0.1.9

1 year ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.2

2 years ago

0.1.3

2 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.66

3 years ago

0.0.65

3 years ago

0.0.63

3 years ago

0.0.64

3 years ago

0.0.62

3 years ago

0.0.61

3 years ago

0.0.60

3 years ago

0.0.59

3 years ago

0.0.58

3 years ago

0.0.57

3 years ago

0.0.56

3 years ago

0.0.55

3 years ago

0.0.54

3 years ago

0.0.53

3 years ago

0.0.51

3 years ago

0.0.52

3 years ago

0.0.50

3 years ago

0.0.49

3 years ago

0.0.48

3 years ago

0.0.47

3 years ago

0.0.46

3 years ago

0.0.45

3 years ago

0.0.44

3 years ago

0.0.43

3 years ago

0.0.42

3 years ago

0.0.40

3 years ago

0.0.38

3 years ago

0.0.39

3 years ago

0.0.37

3 years ago

0.0.36

3 years ago

0.0.35

3 years ago

0.0.34

3 years ago

0.0.33

3 years ago

0.0.32

3 years ago

0.0.31

3 years ago

0.0.30

4 years ago

0.0.29

4 years ago

0.0.27

4 years ago

0.0.28

4 years ago

0.0.26

4 years ago

0.0.25

4 years ago

0.0.24

4 years ago

0.0.23

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.17

4 years ago

0.0.18

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.14

4 years ago

0.0.12

4 years ago

0.0.13

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago