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

@mini-dev/view-support

v0.1.1

Published

mini app view support

Downloads

4

Readme

ViewSupport

为自定义小程序组件提供的辅助方法,主要包含两类功能:

  1. 创建预设构造器;
  2. 管理组件间关系。

安装

npm install @mini-dev/view-support

创建预设构造方法

小程序只提供了基于 Behavior 的复用机制,因此,本库提供了基于 option 和 Function 的复用方式。

重要说明:由于 Behavior 本身有自己的优先级定义,因此,对于 Behavior 自身已经支持的属性, 建议使用 Behavior 来定义,只有 Behavior 不支持的属性,才考虑使用 Option 的方式进行复用。

Behavior 自身已经支持的属性包括:

properties
data
observers
methods
behaviors
created
attached
ready
moved
detached
relations
lifetimes
pageLifetimes
definitionFilter

更新更详细的文档参见官方文档:https://developers.weixin.qq.com/miniprogram/dev/reference/api/Behavior.html

1、 创建预设组件

const {presets} = require("@mini-dev/view-support");

export const MyComponent = presets.Component({
    externalClasses: ['xxx-class'],
    options: {
        styleIsolation: 'isolated',
        multipleSlots: true,
        pureDataPattern: /^_mini/
    }
});

3、 调用预设组件

MyComponent({
    properties: {},
    data: {},
    methods: {}
});

默认使用小程序框架的 Component 来创建组件。

4、 组合调用

如果想使用其他已封装的 Component 构造方法,也可以通过参数显式指定,以预置的 MiniComponent 为例:

const {defaults} = require("@mini-dev/view-support");

MyComponent({
    properties: {},
    data: {},
    methods: {}
}, defaults.MiniComponent);

或者在创建的时候直接绑定:

const {presets, defaults} = require("@mini-dev/view-support");

const MyComponent = presets.Component({
    ...
}, defaults.MiniComponent);

MyComponent({
    ...
});

但是这两种方式有一个重大差异:presets.Component 的参数是作为预设值参与合并的,因此优先级比调用时传值要低。

管理组件间关系

1、创建一个关系

const {relations} = require("@mini-dev/view-support");

export const {parent, child} = relations.createParentChild();

2、配置关系节点

父节点(parent.wxml, parent.js)


parent({
    methods: {
        onRelationChanged(event, child) {
            //...
        }
    }
});

子节点(child.wxml, child.js)


child({
    properties: {
        show: {
            type: Boolean,
            value: false
        },
        tag: {
            type: String,
            value: ''
        }
    },
    methods: {
        onRelationChanged(event, parent) {
            //...
        }
    }
});

父级组件可以通过 getRelationChildren 获取子级组件(Node List)。 子级组件可以通过 getRelationParent 获取父级组件(A Node)。

3、正常使用组件

<parent mini-data="{{active}}">
    <child tag="t1" />
    <child tag="t2" />
</parent>

也可以直接导入查看 demo

ChangeLog

0.1.1

  1. relations 增加一对多的关系。
  2. presets 增加。
  3. defaults.MiniComponent 增加 virtualHost: true 默认配置。

0.1.0

  1. API 不兼容调整。

0.0.5

  1. 支持多个构造器。

0.0.4

  1. 增加日志。

0.0.3

  1. 增加 Page 相关方法。
  2. 合并组件关系库。