Giter Club home page Giter Club logo

reduxular's Introduction

reduxular

needed explanations:

  • Reduxular Element: put all state in store, class members aren't guaranteed to be initialized before state listeners are fired.
  • Initial state must contain all state properties (type guards will prevent this if using TypeScript)

reduxular's People

Contributors

dependabot[bot] avatar electrovir avatar lastmjs avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

reduxular's Issues

Write tests

Once it is working in multiple projects, add some amazing tests

Fails tsc

When I have a typescript project that depends on this through npm and then I try to use tsc to transpile my project it fails with several errors from reduxular. Excluding node_modules doesn't help neither does adding "skipLibCheck": true to compilerOptions in tsconfig.json.

I suggest that the published package includes only already-transpiled (.js) files and include the type definitions.

Get rid of all any's

The types are really good right now, but we have a few any's laying around. Get rid of them and make the types perfect

Consider exposing root reducer on store

Right now there is no official way to get to the generated root reducer when using createObjectStore. We can provide a custom reducer that is combined with the root reducer, but we can't get to the root reducer itself. My use case for this is performing tasks after the state has been updated, for example persisting the entire state to local storage. I can do it in a listener, but it might be nice to create reducer that encapsulates this functionality, a pattern I've used elsewhere

Add a state property to the store

It's becoming common for me to create a special action called RESET_STATE just to set the state back to the InitialState inside of a component. I would love a property called state that would simply do this for me. And that would be nice

Write article

Once it is working in multiple projects, write an amazing article and spread the word

optional properties never get set

If the state type generic contains an optional property and that property is correctly omitted from the initial state in the constructor, the property never gets set afterwards even when consumers attempt to do so.

Example component:

import {html, render as litRender} from 'lit-html';
import {ReduxularElement} from '../../reduxular-element';

type State = {
    // NOTE: this is optional!
    optionalCount?: number;
};

// This initial state is valid!
const initialState: Readonly<State> = {};

class ReduxularElementTestOptionalProperty extends ReduxularElement<State> {
    constructor() {
        super(initialState, state => {
            litRender(this.render(state), this);
        });
    }

    render(state: Readonly<State>) {
        console.log('reduxular-element-test-optional-property:', state.optionalCount);

        return html`
            <div>reduxular-element-test-optional-property: ${state.optionalCount}</div>
        `;
    }
}

window.customElements.define('reduxular-element-test-optional-property', ReduxularElementTestOptionalProperty);

To see in action add the following to reduxular-app.ts's render method output:

<reduxular-element-test-optional-property .optionalCount=${state.count}></reduxular-element-test-optional-property>

Notice that the count value of reduxular-element-test-optional-property never updates.

Find way to use top level component for all state

It would be really nice to allow the top level component to hold all state, and pass state down to each component through props. This would make each child component in the tree more modular, without a dependency on a global Redux store. The big problem I see is making updates to the global store from within child components. There are a couple ways I can see to do it. One way is to raise an event when the global store needs to change. The top level component can register listeners for those events and then dispatch onto its store. The event handling will be asynchronous though, which might have drawbacks. It gets rid of the possibility of updating global state synchronously, and you have no way of awaiting the state change as far as I can tell.

Another way is to export the top level or pass it down through the props. But then that kind of defeats the while purpose of lossely-coupling the components and the global store. We've just added the dependency back.

If we can figure out how to await the global store change, that might work.

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.