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

applets-store

v0.1.0

Published

小程序的全局状态管理工具,你可以理解为小程序版的vuex

Downloads

10

Readme

applets-store -- 专为小程序开发的"状态管理模式"

帮助小程序开发者,通过使用 applets-store 提供的 page、component 替代原 Page、Component,即可直接调用$store,做全局变量管理,并且会同步更新页面。

Install

$ npm i applets-store -s

Page 使用方法

page.js

import { page as storePage } from 'applets-store';
storePage({
  // $store 声明配置 [必须]
  $store: {
    // 声明 $store.agreeNum (只有声明后的变量才能在当前页使用)
    agreeNum: {
      default: 0 //默认值 [非必须,推荐写上,健壮代码的同时,还可以提示变量类型]
      observer: 'onChange_agreeNum',
    }
  },
  onShow(){
    let { $store } = this.data;
    console.log('$store.agreeNum',$store.agreeNum)
    // 直接对变量赋值即可,不用像小程序通过setData赋值
    $store.agreeNum += 1;
  },
  onChange_agreeNum(newVal) {
    console.log('page onChange $store.agreeNum', newVal);
  },
})

page.html

<view class="container">
  <view>Agree:{{ $store.agreeNum }}</view>
</view>

Component 使用方法

component.js (基本与 page 中使用一致)

import { component as storeComponent } from 'applets-store';
storeComponent({
  $store: {
    agreeNum: {
      observer: 'onChange_agreeNum',
      default: 0
    }
  },
  attached() {
    let { $store } = this.data;
    console.log('输出全部全局变量$store', $store);
    $store.agreeNum += 1;
  },
  methods: {
    onChange_agreeNum(newVal) {
      console.log('component onChange $store.agreeNum', newVal);
    }
  }
});

component.html

<view class="container">
  <view>Agree:{{ $store.agreeNum }}</view>
</view>

Demo

还没看懂?没关系,这里有现成的 Demo