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

reedx

v0.1.2

Published

Like redux but with less code

Downloads

5

Readme

Reedx

Vantagens

  • Like redux, porém com menos boilerplate e teorias.
  • Sem necessidade de instalar vários packages.
  • Sem reducers, actions, types, whatevers.
  • Integra normalmente com as libs do Redux (middlewares, devtools, etc).

Arquitetura

Model

Um model é responsável por guardar dados e expor métodos. Não é possível modificar um model senão for atráves de um método (reducer) responsável por isso.

Reducers

São os métodos responsáveis por modificar as propriedades base de um model. Um reducer pode modificar apenas o seu próprio model.

Computed

Colocar muita lógica referente ao seu model nos reducers não é a melhor maneira de tornar seu código readable. Para isso existe as computed properties, que são propriedades não armazenadas na memória do seu model, mas que serão expostas ao conectar o mesmo em algum componente. Este conceito é algo muito parecido do que é possível com os seletores no Redux.

Types

  • Model: { [key:string]: any }
  • Action: Object<type: string, payload: any, error: boolean>
  • Reducer: { [key: string]: (state: Model, action: Action) => void }
  • Computed: { [key: string]: (state: Model, props: Object) => any }

API

model({ name, state, computed, reducers })

params

  • name: string
  • state: State
  • computed: Object<Computed>
  • reducers: Object<Reducers>

exemplos

import { model } from 'reedx'

const state = {
  entities: [],
  selectedId: ''
}

const reducers = {
  addUser(state, { payload: user }) {
    return Object.assign({}, state, { entities: [...state.entities, user] }),
  },

  selectUser(state, { payload: id }) {
    return Object.assign({}, state, { selectedId: id })
  }
}

export default model({ name: 'users', state, reducers })

ou usando as computed properties:

import { model } from 'reedx'

const state = {
  entities: [],
  selectedId: ''
}

const computed = {
  user(state) {
    const { users } = state
    return users.entities.find(user => user.id === users.selectedId)
  }
}

const reducers = {
  addUser(state, { payload: user }) {
    return Object.assign({}, state, { entities: [...state.entities, user] }),
  },

  selectUser(state, { payload: id }) {
    return Object.assign({}, state, { selectedId: id })
  }
}

export default model({ name: 'users', state, computed, reducers })

propsFrom(...models)

params

  • models: Model

exemplos

import React from 'react'
import { connect } from 'react-redux'
import { propsFrom } from 'reedx'

import { users } from './models'

const Users = ({ users, selectedId }) => (
  /* */
)

export default connect(propsFrom(users))(Users)

handlersFrom(...models)

params

  • models: Model

exemplo

import React from 'react'
import { connect } from 'react-redux'
import { propsFrom, handlersFrom } from 'reedx'

import { users } from './models'

const Users = ({ users, selectedId, selectUser }) => (
  /* */
)

export default connect(propsFrom(users), handlersFrom(users))

pick(model, properties)

params

  • model: Model
  • properties: Array<string>

exemplo

import { model, propsFrom, pick } from 'reedx'

const users = model({
  name: 'users',
  state: {
    all: [],
    selectedId: null,
  }
})

const mapProps = propsFrom(
  pick(users, ['selectedId']))
)

console.log(mapProps({ users })) // { selectedId }

omit(model, properties)

params

  • model: Model
  • properties: Array<string>

exemplo

import { model, propsFrom, omit } from 'reedx'

const users = model({
  name: 'users',
  state: {
    all: [],
    selectedId: null,
  }
})

const mapProps = propsFrom(
  omit(users, ['selectedId']))
)

console.log(mapProps({ users })) // { all }

Renomeando propriedades ao conectar

Algumas vezes você pode ter proprieades com o mesmo valor entre models diferentes e ter a necessidade de conectar os dois na mesma view. Neste cenário, você teria a última propriedade sobrescrevendo a primeira devido aos seus valores serem iguais. Para evitar isso, basta você setar o novo nome da sua variável usando : após a definição no método de pick ou omit

import { model, propsFrom, pick } from 'reedx'

const users = model({
  name: 'users',
  state: {
    otherProp: null,
  }
})

const mapProps = propsFrom(
  pick(users, ['otherProp:prop'])
)

console.log(mapProps({ users })) // { prop }