creode/personalised-data
最新稳定版本:1.0.2
Composer 安装命令:
composer require creode/personalised-data
包简介
Creates a new hookable endpoint allowing you to populate personalised user data through a single url.
README 文档
README
This package is designed to be used on sites where dynamic data needs to be hydrated into the page at certain intervals. This is useful for sites that are built with a static site generator, or where the initial page load is slow due to the amount of data that needs to be loaded.
Installation
composer require creode/personalised-data
Usage
The package is designed to be used with a Laravel application. The package provides a Blade directive that can be used to define the data that needs to be loaded into the page after the initial page load.
Blade Directive
The Blade directive is @personalisedData and will handle the registration of the initialisation script and needs to be placed within your blade layout file.
@personalisedData
Registering data
Data to be returned from the personalised data module can be defined by attaching a callable with a key and return data to the attach function of the Creode\PersonalisedData\Services\PersonalisedData service class.
use Creode\PersonalisedData\Services\PersonalisedData; PersonalisedData::attach('product_comparisons', function() { $productIds = app(StorageInterface::class)->get(); return ProductRepository::with(['featuredImage', 'category'])->find($productIds); });
Hydrating data
The data attribute fires off a JavaScript window event, with a detail parameter containing all of the personalised data. Once loaded submodules can listen to and act upon to attach the data to the page.
document.addEventListener('getPersonalisedDataComplete', (e) => { for (let product of e.detail.product_comparisons) { store.add(product); } });
统计信息
- 总下载量: 20
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2024-09-25