承接 dewsign/pusher-agent 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dewsign/pusher-agent

Composer 安装命令:

composer require dewsign/pusher-agent

包简介

Vuex/Axios/Pusher store to enable SPAs to work with remote data without needing to interact with Ajax

README 文档

README

npm

Authors:

Overview

A namespaced Vuex store module that makes use of AJAX to get and update the store's data from the given API end-point.

Usage

To use the AJAX Vuex store in your application, start by extending the AjaxStore class from your own store class, such as below:

import { AjaxStore } from 'ajax-store'

class ExampleStore extends AjaxStore {
    constructor() {
        super({
            action: 'https://example.com',
            method: 'GET', // Default
        })
    }
}

export default ExampleStore

You can specify the AJAX request 'action' and 'method' when calling the parent class' constructor.

Import your newly created namespaced store module into your Vuex store, for example:

import Vue from 'vue'
import Vuex from 'vuex'

import ExampleStore from './ExampleStore'

Vue.use(Vuex)

const VuexStore = new Vuex.Store({
    modules: {
        example: new ExampleStore(),
    },
})

export default VuexStore

To get data from the namespaced Vuex store (or to update it) in your Vue component, you can make use of the Vuex mapGetters and mapActions helper methods. Below is an example implementation of a Vue component that checks if the namespaced Vuex store contains any items during the created lifecycle hook. If the store contains no items, then the updateItems action is dispatched to get the items from the given API end-point specified in your namespaced store module using AJAX.

import { mapGetters, mapActions } from 'vuex'

created() {
    if (!this.hasItems) this.updateItems()
},

computed: {
    ...mapGetters('example', [
        'items',
        'hasItems',
    ]),
},

methods: {
    ...mapActions('example', [
        'updateItems',
    ]),
},

PusherAgent for Laravel Echo with Pusher

The agent will listen for any updates from the api and commit them into the current state to ensure all connected clients are in-sync and remove the need for regular ajax calls to fetch the latest data.

IMPORTANT: The agent will automatically listen to private pusher channels with the same name as the Vuex Store Module defined earlier. In this case example (private-example). This should also match the name of your Laravel Model class.

When creating your root Vue instance, add the PusherAgent plugin and mixin.

import Vue from 'vue'
import { PusherAgent } from 'ajax-store'

Vue.use(PusherAgent.plugin, {
    key: 'your pusher key',
    cluster: 'eu',
    encrypted: true,
})

new Vue({
    el: '#app',
    template: '<App/>',
    components: {
        App,
    },
    mixins: [
        PusherAgent.mixin,
    ]
})

Gotchas

The BroadcastsPusherEvents trait will set the wasRecentlyCreated property of a model to false after the first saved event hook. This means that a new model can be instanciated with create() which fires a save event and any further saves on the model will be treated as an update. This is useful when associating many-to-many relations with the model which require the model to be present in the database.

dewsign/pusher-agent 适用场景与选型建议

dewsign/pusher-agent 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 53 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 05 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 dewsign/pusher-agent 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dewsign/pusher-agent 我们能提供哪些服务?
定制开发 / 二次开发

基于 dewsign/pusher-agent 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 53
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2018-05-23