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

vuex-lens

v0.0.2

Published

* 开始你的优雅状态管理

Downloads

2

Readme

  • 开始你的优雅状态管理

    因为vue内建类型的特性使得写代码的时候失去了很多JavaScript强大的功能。特别是喜欢functional的同学在处理列表时只能用蹩脚的vue.array定义的方法解决问题。这些都给我们操作数据(大部份时列表数据)时带来不可忽视的开发体验。这也是vuex-lens存在的原因,用一种更加优雅的方式去解决数据更新问题。

    lenses为一个古老的functional programming概念,这里不作太多解释了,如果没使用过的同学下面找了一些资料。

    https://medium.com/javascript-inside/an-introduction-into-lenses-in-javascript-e494948d1ea5

    http://fluffynukeit.com/how-functional-programming-lenses-work/

    这里我留言了一个通俗解释 http://functional-programming.cn/t/topic/60/2?u=qquanwei

  • 安装

npm install vuex-lens --save
  • 例子

** 创建lenses

import { propLens, lens } from 'vuex-lens';

const nameL = propLens('name');
const nameL = lens((obj) => obj.name, (value, obj) => obj.name = value);

** 获取值


import { get } from 'vuex-lens';

const obj = { name: 'Alice' };
const name = get(nameL, obj);

console.log(name)  // -> Alice

** 简单写入

import { set } from 'vuex-lens';

const obj = { name: 'Alice' };

set(nameL, 'Bob', obj); // 返回obj相同的对象, 此时会产生副作用 obj.name 已经被修改,会触发vue的依赖更新

console.log(obj.name) // -> Bob

** transformer


import { over } from 'vuex-lens';
import { difference } from 'lodsh/difference';

const differencer = (a) => (b) => difference(b, a);

const array1 = [1,2,3,4,5,6,7,8,9];

const obj = {
  list: array1
};

const array2 = [3,5,6];

// 想实现的功能是 array1 - array2. 也就是difference(array1, array2);


const listL = propLens('list');

over(listL, differencer(array2), obj); // 此时obj.list为减去3,5,6的list1数组,且会触发vue的依赖更新。

** form 的更新

import { lensToVueLens, lens } from 'vuex-lens';