Code Monkey home page Code Monkey logo

smalldots's Introduction

Smalldots

Smart modules for React.

npm

Available Scripts

In the project directory, you can run:

yarn install

Installs the project dependencies.

yarn start

Runs the docs in the development mode.
Open http://localhost:3000 to view it in the browser.

yarn build

Builds the library and docs for production.

smalldots's People

Contributors

dependabot[bot] avatar fidelisclayton avatar hnordt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smalldots's Issues

Authentication Module

I would like to propose a decoupled authentication module for Redux.

The idea is that this module should be generic, you should be able to use it with oAuth, Passport, Auth0, your custom backend, etc.

In the future we'll also build an authorization module.

The first step is create a common API, here is the first draft:

function login() {}

function logout() {}

function signup() {}

function resetPassword() {}

function changePassword() {}

Implement <Auth /> based on Auth0

Probably it'll need to be placed under a separated repository as it'll need to important Auth0 JavaScript library.

I think that would be best to split all modules (smalldots) into separated repositories, each repository being a smalldot :D

Long page-list Paginator

First of all, very nice project...

I was wondering how (and if) I could use the Pagination component to achieve the result I have with very long page-lists:

When I have 1st page selected, I get:
image

When I have one "middle" page selected, I get this:
image

I can use range(1,3) to render the 3-first and range(numberOfPages -3, numberOfPages ) to the 3-last pages I always show... But that would make me repeat the rendering code 3-times...

For the "longer-step" intervals, I'm no sure how to deal with it...

Maybe I should extends (sub-class) from your Component, re-writing only the getPageRange function??
In the result list, I could return non-integer (null) for non-pages ... rendering....

Fetch componentWillReceiveProps

Currently, on Fetch's componentWillReceiveProps, it does the following:

componentWillReceiveProps(nextProps) {
    if (!this.props.lazy && !isEqual(this.props, nextProps)) {
      this.fetch()
    }
  }

I have a use case that depending on the parent's props, the Fetch's lazy prop should change between true and false.
In that case, if the initial prop was true, it will never fetch again.

My solution was the following:

componentWillReceiveProps(nextProps) {
    if (!nextProps.lazy) {
      this.fetch()
    }
  }

What do you think?

import { Form, Validator } from 'smalldots'; do not work

import { Form, Validator } from 'smalldots';

I think it is common to be able to import component from the same global name instead of having to use different paths for different components

this works, but it is not so simple as the version above

import Form from 'smalldots/lib/Form';
import Validator from 'smalldots/lib/Validator';

I guess that webpack or webpack 2 are smart enough to remove files that are not used

Object.freeze

State/props passed to children() shouldn't be mutated.

  render() {
    return this.props.children({ data: this.state.data, error: this.state.error })
  }

In this example data and error shouldn't mutated by the consumer.

To prevent mutation, I think that we can do something like this:

  render() {
    const frozenState = deepFreeze({ ...this.state })
    return this.props.children(frozenState)
  }

Implement <Search />

Proposed API:

const searchQuery = {
  name: 'h',
  age: { $gt: 17, $lt: 66 },
  likes: { $in: ['react', 'jsx'] }
}

const App = () => (
  <Fetch path="/users">
    {({ data: users }) => (
      <Search dataSource={users} query={searchQuery}>
        {({ results: filteredUsers }) => (
          <UserList users={filteredUsers}  />
        )}
      </Search>
    )}
  </Fetch>
)

Feedback: https://twitter.com/hnordt/status/773241068548685824

Fetch component implicit behavior

  componentDidMount() {
    if (!this.props.lazy) {
      this.fetch()
    }
  }

If user didn't defined lazy prop then it's gonna be undefined, but !undefined converts to true.
So Fetch is not lazy by default.

Exemplo

Vi a gravação video da BrazilJS e ficou um pouco dificil acompanhar os exemplos.
Acho que perdi alguma coisa e meu teste não funcionou.
Só consigo fazer o get, mas o valor não é atualizado no render.
Minha intenção aqui é usar a store só para armazenar temporariamente.

import React from 'react';
import {SyncStorage} from 'smalldots'

const defaultValue = {
  number: 222
}

const MemStore = props => (
  <SyncStorage
    {...props}
    driver={{
      getItem: key => defaultValue[key],
      setItem: (key, value) => {
        defaultValue[key] = value
        return value
      }
    }}
  />
)

export default class App extends React.Component {
  render(){
    return (
      <MemStore subscribeTo="number">
        {({setItem, getItem, number}) => {
          return (
            <div>
              <p>my number: {number}</p>
              <p>getItem: {getItem('number')}</p>
              <button onClick={() => setItem('number', 1000)}>setItem</button>
            </div>
          )
        }}
      </MemStore>
    )
  }
} 

Form`s values does not update when change initialValues

Currently, on Form's componentWillReceiveProps, it does the following:

componentWillReceiveProps(nextProps) {
    if (!isEqual(this.props.initialValues, nextProps.initialValues)) {
        this.setState(prevState => ({
            values: { ...nextProps.initialValues, ...prevState.values }
        }))
    }
}

When I update initialValues prop, the values ​​are not updated.
My solution was to change the merge order of the props, like this:

componentWillReceiveProps(nextProps) {
    if (!isEqual(this.props.initialValues, nextProps.initialValues)) {
        this.setState(prevState => ({
            values: { ...prevState.values, ...nextProps.initialValues }
        }))
    }
}

What do you think?

(I'm sorry for the English, it's not my native language.)

isDirty for a single field

I wanted to make a form that validates each field only after it's been edited (onChage or onBlur has fired), or alternatively validates all the fields after the user has tried to submit the form.

Can this be done using the Form component? The isDirty field is currently only available for the whole form, not single fields.

<Paginator /> - Is the intent of getPageRange() clear?

I don't know if getRangePage() is a good name for the method that returns the page range (it accepts an offset).

The current API is getPageRange(offset), if the current page is 10 and you pass an offset 3, it would return [7, 8, 9, 10, 11, 12, 13].

I would like to hear thoughts on this. getPages() is an option, but as Paginator passes down page, I think it would be confusing to have page and getPages(), in that case getPageRange(), is more clear in my opinion.

Improve docs

From where should I import Fetch, Form, Validator and so on?

what params or fields Form can use?

Bulma Support

  • Responsive helpers
  • Basic grid
  • Responsive grids
  • Tiles
  • Boxes
  • Basic buttons
  • Block buttons
  • Button groups
  • Button addons
  • Content
  • Forms
  • Icons
  • Images
  • Notifications
  • Progress bars
  • Tables
  • Tags
  • Titles
  • Cards
  • Levels
  • Media objects
  • Menus
  • Messages
  • Modals
  • Navs
  • Pagination
  • Panels
  • Tabs
  • Containers
  • Heroes
  • Sections
  • Footer

componentWillReceiveProps calling dispatch with old props

I have a use case where I am using Fetch, and I am changing the url parameter.
This calls the internal componentWillReceiveProps method in Fetch, which again calls this.dispatch(nextProps.body).

My problem is that the dispatch is called again with the previous url, not the url i updated to. I suspect this is because dispatch is not passed the new props, and is hence using the old ones.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.