npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sandload/open-store-sdk

v1.0.19

Published

开个店前端SDK

Downloads

8

Readme

为什么引入SDK概念

  1. 规范入参出参的数据格式,目前服务端提供的数据格式问题
  2. 规范前端基础业务逻辑
  3. 规范异常情况的处理(目前很多页面逻辑未处理异常场景的)
  4. 多端支持,目前我们的api模块仅支持项目本身,脱离项目无法复用,耦合性过高,跟页面强依赖
  5. 满足函数式编程

SDK工程

  • 数据转换映射
此部分待完善,以及必要性评估
  • 业务基础数据类型定义,类似money、distance
针对sdk输出的数据类型做严格控制,该返回null,不返回类似''或{}等
  • fetch项目内需要可配置化
暂定fetch内置,仅提供必要异步回调
  • 接口的内聚
sevices为单一职责服务, logic为逻辑组合

servces为正常code
logic中的code会存在为自定义情况
  • SDK边界划分
SDK只处理数据,绝不处理与UI相关、页面业务相关的交互
  • 异常、数据的捕获上报

小程序工程

SDK功能

export default {
    config: {
        env: 0,
        host: '',
        constCode: [],
        accessToken: '',
        partnerId: '1864'
    },
    commonParams: {
        storeId: '',
        sessionId: ''
    },
    header: {},
    adapter: {
        beforeRequest(config){
            
        },
        afterRequest(response){
            return Promise.resolve();
        }
    },
    state: {},
    utils: {
        _: lodash
    },
    service: {
        store,
        product,
        config,
        member,
        address,
        cart,
        activity,
        ...
    },
    logic: {
        // 基于service的二次封装,固定的流程页面,提供方便快速搭建跑通流程
        home: {},
        pickup: {},
        take: {},
        mine: {},
        orderSubmit: {},
        userInfo: {}
    }
}

如何使用SDK

import sdk from 'fm-sdk';
import { beforeRequest, afterRequest } from './fetch.js';

export default {
    onLaunch() {
        let ext = getExt();
        // 初始化配置
        let fm = sdk.init({
            config: {
                appId: 'wxef754bdcc220db4e',
                partnerId: '2399',
                baseURL: 'https://open-store.sandload.cn',
            },
            adapter: {
                // 可将adapter部分抽离到独立的模块
                beforeRequest(config) {
                    
                },
                afterRequest(response, options) {
                    // 1.在这里做一系列额外处理,例如弹框提示,但是注意这里无法更
                    // 2.改后续进入service的值,sdk提供足够的拓展,
                    // 3.但提供拓展的目的旨在让控制交互的权利释放,不代表有能力干扰sdk,例如这里的afterRequest无法干扰sdk正常运行
                    // options提供
                    if (response.success) {
                        // 成功可以无视
                    } else {
                        uni.showToast();
                        uni.FM.reportLog();
                    }
                }
            }
        });
        uni.FM = fm;
    },
    onError(error){
        // sdk错误上报
        uni.FM.reportLog(1, {
            <!--需要上报的数据-->
            error,
            ...params
        });
    }
}

页面使用

export default class pickup {
    construct(){
        this.a = a;
        
        this.callback = function(){}
        
        this.init();
    }
    init(){
        let params = {};
        uni.FM.logic.member.getApiData(params).then(res=>{
            this.callback();
        });
    }
    hasStore(){
        
    }
    hasMenuAndCategary(){
        
    }
    
}

Page

调用1
onLoad(){
    let params = { orderType: 1 };
    uni.fm.service.cart.getData(params).then(res=>{
    
    }).catch(err=>{
    
    })
}

调用2

onLoad(){
    let params = { orderType: 1 };
    let instance = uni.fm.logic.pickup(params);
    instance.on('init', function() {
        
    });
}