Giter Club home page Giter Club logo

Comments (20)

fi0rini avatar fi0rini commented on September 11, 2024

Yeah Lisa, I agree.

The initial work patterns have been variable, as you noticed. Iโ€™ve been experimenting and prototyping methods/patterns. I think its best for us to navigate away from the initialize pattern like you've mentioned and start breaking the components apart and decoupling them so they are more modular. I can check in a branch when I think I have some stuff to work with but I'm still experimenting with these features.

Thereโ€™s a lot of architectural work that needs to be done in my opinion; Backend and front-end.

Should we discuss this on Saturday?

Nick

On Feb 24, 2016, at 8:03 PM, Lisa Cho [email protected] wrote:

There's tons of calls to retrieve data from the API but the app is very inconsistent in terms of how information is passed, where API calls to fetch data are made, how the views update themselves. Can we discuss the advantages/disadvantages and standardize it? Not sure what pattern to follow because there's so many in the app.

Sometimes there is an APIWorker, sometimes there isn't. It makes it harder to work with.
Some (Opinions.jsx) directly make AJAX calls within the component, passing in setState).
Others (Ballot.jsx) call a Store initialize or retrieve method, passing in setState. Store's method in turn calls APIWorkers, eventually resolving promise and calling the callback(the setState).
Others (PositionItem.jsx) call a Store retrieve method. Store calls APIWorkers, which fire an action when the data is retrieved. AppDispatcher register event, updates the store and emits change, which updates the component because component has registered changeListener.
There are other minor variations of these patterns....
โ€”
Reply to this email directly or view it on GitHub #105.

from webapp.

DaleMcGrew avatar DaleMcGrew commented on September 11, 2024

@nf071590 Can you create a brief cheat sheet of the WebApp code that you think we should be emulating for now, vs what we shouldn't? For example, you had said that we were moving away from API Worker, and that was helpful for me to know.

from webapp.

fi0rini avatar fi0rini commented on September 11, 2024

I think that Opinions should generally make a network request every time a user navigates to the Opinions route when the store doesn't have 20 orgs in it... This way the user can grab a more Orgs to follow or ignore and remove them from the Org store.... Does that make sense?

from webapp.

fi0rini avatar fi0rini commented on September 11, 2024

@DaleMcGrew Yeah, i'm working on some framework level stuff, been experimenting and prototyping with FluxStore and I will let you know when I have what I think is a good pattern. I'm not sure if there is a 1 size fits all answer to the project but I'll be brainstorming more today...

I wasn't expecting everyone to follow the same pattern of BallotStore initially, I was trying to get something up and working, and it was a childlike attempt at linking Flux and React with the network. Now that we have a deeper understanding of React and Flux, we should be able to refactor to break components apart and modularize them.

I'm trying to figure out the best way to slip network calls into the Action --> Dispatcher --> Event graph... It seems like it would go in between the Action/Dispatcher. So I want to break apart the Flux architecture so that we can slip our endpoints into it and our Action/Dispatcher system can be smart enough to grab data from the server when it needs to, then store it, then return it to the component... I have something like this working on my local but it isn't necessarily that pretty.

But then on top of that I'd like a way for us to be able to create components that are wrapped in their own action Action/Dispatcher/Store... Probably using the decorator pattern I've seen before...

I still need to clean this stuff up and try to figure out what is the optimal solution.

Also creating Action/Dispatcher dependencies is another major key. I'm trying to figuring out how Facebook engineers use the waitFor method to create dependencies between stores, this is important and I need to work on figuring out that aspect of their architecture I believe.

If anyone has input on this, please don't be shy.

from webapp.

DaleMcGrew avatar DaleMcGrew commented on September 11, 2024

@nf071590 I agree we should "freshen up" the data frequently, yes. Ideally when you retrurn to the "More Opinions" page, we would display the orgs that are already in the local VoterGuideStore before retrieving more, so the "Loading" swirl shows up at the bottom of the existing data, and voters don't have to wait. PS. great work on the Opinions page Nick!

from webapp.

fi0rini avatar fi0rini commented on September 11, 2024

@DaleMcGrew thanks Dale!

from webapp.

lisamburns avatar lisamburns commented on September 11, 2024

Thinking about this more and also listening to some talks, I like using the idea of waitFor, and thinking of data loading as being caused by user actions (just the same as the user action FOLLOW or UNFOLLOW). IE would could have the action START_APP, which is fired by just loading the thing. The VoterStore could subscribe to the event and fetch the Voter. The BallotStore could fetch the Ballot. The Dispatcher could waitFor the Voter to finish fetching and then tell the BallotStore to fetch the Ballot. (Since it's possible there's more than one ballot, we may also want to separate out a Candidate and MeasureStore, which could then start fetching its items once BallotStore finishes fetching.). Another action could be VIEW_CANDIDATE, which causes individual positions to be fetched into the position store.

from webapp.

lisamburns avatar lisamburns commented on September 11, 2024

My other comment is that a lot of dependencies are caused by the structure of the API (i.e. some only accept regular ID and type (CANDIDATE or MEASURE), whereas we only have WE_VOTE_ID. Hence I'd try to get the ID and type from the BallotStore to call an API and it would be empty, so I'd have to wait for something to finish fetching to get the ID and TYPE from the store, and then call the API. If the API accepted we_vote_id uniformly, then no waiting (at least in this case) would be required.

from webapp.

DaleMcGrew avatar DaleMcGrew commented on September 11, 2024

Thank you @lisamcho, I am in the process of making sure all API endpoints accept we_vote_id as an input variable. If you need any in particular now, please let me know.

from webapp.

lisamburns avatar lisamburns commented on September 11, 2024

Another idea I heard at a tech talk and liked that I haven't used myself is separating presentational vs container components. A lot of my components initialize their state to what they get by props, then setState onChange. The other idea is that you try to get as much of the data connectivity into the state of a container component (all fetching and setting of State), and then the subcomponents only need to receive and sdisplay their props.

from webapp.

lisamburns avatar lisamburns commented on September 11, 2024

@DaleMcGrew yes that would be great!

from webapp.

fi0rini avatar fi0rini commented on September 11, 2024

I think I found a really clean way to approach the initialization problem... I can check this into a new branch if anyone is interested in taking a look...

from webapp.

lisamburns avatar lisamburns commented on September 11, 2024

I'd like to see! @nf071590

from webapp.

fi0rini avatar fi0rini commented on September 11, 2024

@lisamcho checkout the new flux-prototype branch, ballots are the only thing that has changed and I did not do any additional work but to load additional data etc. It only does one request to populate page.

checkout the files
src/js/dispatcher/dispatcher.js (to see the dispatcher prototype extension)
src/js/actions/BallotActions.js (to see the BallotAction.init definition, which is called in the src/js/routes/Ballot/Ballot.jsx when componentDidMount is invoked )
src/js/stores/BallotStore.js (which sets the state of the Store and emits a change back to the ballot)
src/js/routes/Ballot/Ballot.jsx (to see where it listens for the change and then updates the state and renders the view)

from webapp.

fi0rini avatar fi0rini commented on September 11, 2024

What I like about this approach is that it allows stores to subscribe to network requests and populate when they return... Also network errors,which could probably prove to be useful... Ex:

try{ Action.init() } catch (e) { // ERROR LOADING BALLOT // handle error logic at ui level }

from webapp.

fi0rini avatar fi0rini commented on September 11, 2024

Or possibly subscribe components to error events and trigger them on a network error is another possibility

from webapp.

DaleMcGrew avatar DaleMcGrew commented on September 11, 2024

@nf071590 This sounds like a good approach. Great work!

from webapp.

lisamburns avatar lisamburns commented on September 11, 2024

Hey this is really great! Having the ajax utility take care of creating an action when it returns with name of API endpoint is genius, that will save us a lot of time. I'm onboard with moving in this direction. What about you guys? @pertrai1

from webapp.

fi0rini avatar fi0rini commented on September 11, 2024

The wait for method can hopefully help with endpoint dependencies but I'm
not sure how.
On Feb 27, 2016 11:11 AM, "Lisa Cho" [email protected] wrote:

Hey this is really great! Having the ajax utility take care of creating an
action when it returns with name of API endpoint is genius, that will save
us a lot of time. I'm onboard with moving in this direction. What about you
guys? @pertrai1 https://github.com/pertrai1

โ€”
Reply to this email directly or view it on GitHub
#105 (comment).

from webapp.

pertrai1 avatar pertrai1 commented on September 11, 2024

The major refactor from @lisamcho and @nf071590 should handle this issue and if there are more that are needed, a new issue can be opened up that is based on the refactoring from that change.

from webapp.

Related Issues (20)

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.