Git Product home page Git Product logo

flux-action-class's Introduction

Hi there 👋

ℹ️ My name is Andrey. Rockstar wannabe -> software engineer at Meta hypnotized by AI.

📌 London, UK. UK Global Talent alumni.

💼 Blockchain, web, and a bit of embedded at software consultancies (DSRDataArt) ➡️ Headed front-end at Hazelcast ➡️ Worked on web perf and WASM integration at Bricks ➡️ Enhancing DevX for mobile devs at Meta.

🎓 Voronezh State University, MSc in Computer Science (2009-2014) -> Georgia Tech, MSc in Computer Science (2020-2024).

📝 Blog about life, career, and tech in English and in Russian.

🎤 Fighting my stage fright at conferences. Founded BeerJS in my home town - Voronezh. Program committee member at Geekle.

📚 Running book clubs on Russian classical lit and philosophy in London.

❤️ Philosophy, music (🥁 -> 🎹+🎙), Tolstoy and Dostoevsky, Yesenin, weightlifting, boxing, cycling, hiking, snowboarding.

📫 LinkedInInstagramTelegram, Twitter, Threads.

flux-action-class's People

Stargazers

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

Watchers

 avatar  avatar

Forkers

hovoaep

flux-action-class's Issues

More Code Examples

I like your approach but I find the documentation a little short on some details. Do you think you could provide more examples of actions and reducers in a CRUD scenario? For example, are you creating more classes based on different action types? DataGetSuccess,DataUpdate, DataFilter, etc... If that is the case it would that we would be trading one type of boilerplate for another.

Thank you, and I look forward to reading more.

Type safety loss compared to vanilla ngrx

Consider this example:

interface State {
  a: string;
  b: boolean
}

const initialState: State = { a: '', b: false }

class SetA extends ActionStandard<string> {}
class SetB extends ActionStandard<boolean> {}

function stateReducer(state =  initialState, action: ActionStandard): State {
  switch (action.type) {
    case SetA.type:
      return { ...state, b: action.payload }; // assigning boolean to string, no errors
    case SetB.type:
      return { ...state, a: action.payload }; // assigning string to boolean, no errors
    default:
      return state;
  }
}

To avoid having to cast the action type in every case, the recommended approach is to make the action classes types readonly, and do something like that:

const A_TYPE = 'A';
const B_TYPE = 'B';

class SetA extends Action {
  readonly type = A_TYPE;
  payload: string;
}
class SetB extends Action {
  readonly type = B_TYPE;
  payload: boolean;
}

type MyActions = SetA | SetB;

function stateReducer(state =  initialState, action: MyActions): State {
  switch (action.type) {
    case A_TYPE:
      return { ...state, b: action.payload }; // assigning boolean to string, error
    case B_TYPE:
      return { ...state, a: action.payload }; // assigning string to boolean, error
    default:
      return state;
  }
}

I have been wondering if this is something that would be possible to abstract into a library similar as yours 😄

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.