Code Monkey home page Code Monkey logo

corpuscule's Introduction

๐Ÿ›  Status: In Development

Corpuscule is currently under heavy development. Feedback is always welcome, but be careful with using it in production. API is not ready yet and can receive large changes.

Corpuscule

CI Status GitHub license Coverage Bugs Vulnerabilities

Corpuscule is a set of libraries built on top of Web Components standard. It provides all necessary tools to built whole application from scratch including redux connector, router and form utils.

Principles

Be universal

You can use almost all Corpuscule tools with any Web Component based system, like Polymer, LitElement or SkateJS. They are not bound to @corpuscule/element and implemented with only web components lifecycle hooks. Also, @corpuscule/element can use any renderer you want: lit-html, hyperHTML, preact or even React.

Be small yet powerful

Bundle size matters. It becomes critical for people with a slow internet connection. Corpuscule already uses Web Components standard that takes care of the component system, so everything it needs is to have as many useful features as possible in smallest size as possible.

Be at the bleeding edge of JavaScript

Features adding to the JavaScript language simplify developer's life, give new opportunities and solve problems like security holes. That's why Corpuscule is trying to be on the bleeding edge of language development and use the latest features.

Separate semantics from logic

Semantics is a keystone of the web for a long time now. We used to make our markup as meaningful as possible. We use <article> instead of <div> to wrap our articles because <article> makes way more sense than a simple <div>. We have <header>, <section> and <footer> tags to split our layout to parts properly.

However, with the React popularity growing we have got not only great solutions but also a handful of doubtful patterns. One of them is an approach to put logic into the markup. This approach brings such components as <Provider>, <Suspense>, <Connect(MyComponent)> etc. that can have no own markup at all!

So while it is acceptable for React components since they exist only on the JS level, it could be wrong for web components which have their representation in the DOM. The existence of only logic components in DOM breaks the idea of semantics.

That's why Corpuscule suggests a slightly different approach. Since it is just logic, we can apply it to semantic web components using decorators and class properties. It means that single web component could be a component connected to Redux, custom context provider and router outlet at the same time.

Technologies

Some technological solutions of Corpuscule could be surprising and confusing. This section provides explanation of why this or that solution has been chosen.

Decorators (stage 2)

The new decorators specification could become a game-changer in the JavaScript world (along with private class fields/methods ). Decorators add a powerful system of metaprogramming to the JS language allowing to step into all stages of the class lifecycle, to manipulate class fields in the very declarative yet incredibly flexible way. You still could achieve some similar results using class mixins and static methods with property definition, but it is way less descriptive and has its drawbacks.

Unfortunately, the initial proposal Corpuscule was built on is deprecated due to serious performance issues. There is a new static decorator proposal, but it does not have Babel implementation yet, and it is not defined when it will.

That is the reason Corpuscule moves to an emulation of static decorator proposal. What does emulation mean? Well, it is not a specification-correct implementation, but it implements basic ideas of the proposal. Emulation uses the legacy decorator proposal (stage 1) that is well-supported by Babel and Typescript supplemented with a custom solution: a Babel plugin that adds missing parts to the code generated by the legacy plugin.

Symbols

This solution of Corpuscule may confuse you. You may rarely meet using the regular string-named class fields in Corpuscule tools. Why? Well, the best answer is to avoid naming conflicts. Web components are not React. They won't pack component properties into a separate object this.props. All properties come as class fields. So, to avoid a situation when you want to use property render, but you have a render method that is a heart of your component system, Corpuscule declares all its field names as Symbols. So you are free to use render property along with [render] method, and you are free to create another Symbol named render and use it in the same class. Symbols are unique, and that is their power.

How to use

To work with the Corpuscule project, you have to transpile it using Babel because decorators are not a part of the language yet.

Along with the Babel you have to install @corpuscule/babel-preset that should be used in Babel configuration. This preset contains everything to compile decorators in a way Corpuscule need to work.

Documentation

API documentation is available here.

List of tools

Corpuscule consists of following tools:

  • @corpuscule/context. This package allows creating a context that sends data top-down, from parents to children. Context is DOM-dependent, so using it on different DOM branches with different values you will get different results. It is also a base for many other Corpuscule tools like router or redux.
  • @corpuscule/element. This package provides a set of decorators for creating web components. It is decorator-based analogue for Polymer's LitElement or React.
  • @corpuscule/form. Connector for the ๐Ÿ final-form package that provides Corpuscule solution for forms.
  • @corpuscule/lit-html-renderer. lit-html based renderer for @corpuscule/element. Also includes solution for using custom element class definition as a source for custom element name (MyElement -> my-element) that makes lit-html usage similar to React.
  • @corpuscule/redux. A connector for the Redux library. It is react-redux for Corpuscule.
  • @corpuscule/router. A connector for the Universal Router package, provides Corpuscule solution for routing.
  • @corpuscule/storeon. A connector for the Storeon package, a tiny Redux-like state manager.
  • @corpuscule/styles. A solution for loading CSS stylesheets.
  • @corpuscule/typings. Typescript common typings for the Corpuscule.
  • @corpuscule/utils. This package contains a lot of utilities used in almost all Corpuscule packages. Doesn't have single entrypoint; each util should be loaded separately.

Future

When the static decorator specification reaches stage 3, Corpuscule will be rewritten using it. The current implementation of Corpuscule is done with the basic ideas of the new proposal in mind (that is why it does not use some obvious ideas like a function that creates decorators). It should reduce the number of efforts production code refactoring will take when decorators become a standard.

corpuscule's People

Contributors

lodin 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

Watchers

 avatar  avatar  avatar  avatar

corpuscule's Issues

Simplify @corpuscule/element

For now @corpuscule/element has a lot of things that could be easily removed simplifying code and architecture of a package.

  • Remove lit-html Shady Render
  • Remove Scheduler
  • Move computed

Remove lit-html Shady Render

Since Corpuscule is aiming bleeding edge and browser are getting better and better in support of new technologies, the dynamically imported shady-render could be removed. If the shady-render is still necessary, it could be replaced through the simple babel plugin.

Remove Scheduler

React is still working on it's implementation of async rendering and since Corpuscule position itself as a successor to React, it should be better to wait until the implementation is released rather than to introduce half-baked scheduler that does almost nothing.

Move computed

For now computed is @corpuscule/element built-in. That's not good because it has very insignificant connection to the package core. So I believe it would be better to move it to the separate package @corpuscule/decorator-computed.

Add @element decorator

For some reason @corpuscule/element doesn't contain decorator to define custom element. It should be added as @element decorator.

Refactor back to decorators

Due to new decorator proposal coming soon Corpuscule have to be rewritten back to decorators approach (legacy for now), and it should be the single option to work with framework. It moves framework toward to the goal of using the most bleeding edge technologies.

Suggestion: lit-css support in styles / lit-html renderer

I have been following the progress in this repo for a while, so first of all must admit the great work (especially now when I'm looking through the docs). So let me submit an issue.

Looks like the @style is now accepting either CSS file or raw styles. This is handful, but there is an idea on my mind and I'm not sure where to implement it better.

I would like to add support for lit-css, which is a good way of sharing styles in a way compatible with LitElement. It basically can be already used with raw styles.

Here is the example how it is done in styled-lit-element by the same author: https://github.com/lit-styles/lit-styles/blob/6bea874af7f7b0dc5f8f5e5e5095a68c724792b9/packages/styled-lit-element/src/StyledLitElementMixin.js#L18

Questions:

  1. Can we implement memorization similar to what styled-lit-element does via decorators?
  2. Can we have same decorator applied to the class with different values? Use case is to split components styles into multiple layers, e.g. basic styles and "theme"
  3. How do the inherited classes work with decorators? From what I understand, they should be able to help with organising code better than class mixins (used in Polymer)

Move `computed` feature to a separate package

Computed feature should not be in the main element package since it is a separate feature that is able to exist by itself. So there should be a @corpuscule/computed package containing this feature

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.