Git Product home page Git Product logo

seapig's Issues

Better API documentation

Thank you for this project!

Should we update the API section to include all 4 schema constants?

The current documentation only references OPTIONAL and REQUIREDS, and makes no distinction that plural counterparts exist.

I know that the documentation makes reference to it somewhere in the middle of the docs, but it might be confusing for new developers who jump straight to the API section.

Bundle size seems large based on implementation

I love this library, it does one things and does it well.

I did notice however on bundlephobia that the bundle size is about 7kb which seems pretty large to me since the file size itself is only 2-3kb (comments included).

Would making React a peer Dependency help reduce the bundle size further?

investigate the macro-component syntax

there is a new lib (https://github.com/jxnblk/macro-components) that does pretty much what we are doing it but that have a lot more constraints and is more fragile (jxnblk/macro-components#3).

But the API is pretty neat, looks better than seapig. We could do something similar really easily tho:

instead of

import seapig, { OPTIONAL, REQUIRED } from 'seapig'

const Main = props => {
  const {
    sidebarChildren, // array of children with the `sidebar` prop
    contentChildren  // array of children with the `content` prop
  } = seapig(props.children, { // schema object
    sidebar: OPTIONAL, // sidebar is optional
    content: REQUIRED  // content is required
  })

  // rendering order is always the same
  return (
    <div>
      {sidebarChildren.length && <aside>{sidebarChildren}</aside>}
      <section>{content}</section>
    </div>
  )
}

we could have

import seapig from 'seapig'

const Main = seapig(({
    sidebar,
    content
  }) => {
  return (
    <div>
      {sidebar.length && <aside>{sidebar}</aside>}
      <section>{content}</section>
    </div>
  )
})

we lose the schema but maybe it can be an optional second argument to the seapig function

React warnings for non-boolean attribute

When using seapig and passing on an attribute like so...

<SomeSeapigComponent>
  <h1 foo>Hello World</h1>
</SomeSeapigComponent>

React throws a warning.

screen shot 2018-01-10 at 10 10 16 am

I believe this is because React is trying to render an actual <h1 /> tag with an empty foo attribute.

Should seapig remove the designated props from the component?

We could do this by using React.createElement to clone the child and remove the designated props. It could look something like this:

// https://github.com/enkidevs/seapig/blob/master/src/index.js#L80
Children.toArray(children).forEach(child => {
    if (!child) {
      return;
    }

    const propName = propNames.find(p => child.props[p]) || REST;

    // clone the child and remove the designated prop from it
    const childType = child.type;
    const newProps = { ...child.props };
    delete newProps[propName];
    const newChild = createElement(childType, newProps);

    result[propName === REST ? propName : convertPropname(propName)].push(
      newChild
    );
  });

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.