question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a generic, "core/forms" store for forms

See original GitHub issue

Issue #1211 required some forms that didn’t warrant creating a bunch of actions, selectors, etc. for their data, but we shouldn’t be using useState to manage form data because it requires passing around state from components and negates a lot of the wins we get from using a Redux-backed datastore.

We talked about this on a call today, and we should have a generic, 'core/forms' data store with a very basic API for getting/setting state across forms in the app.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • There should be a new file, assets/js/googlesitekit/datastore/forms, that registers a new form data store, under 'core/forms'.
  • It should provide a single selector: getValue( formName, key )
  • It should provide a single action: setValues( formName, { key: value } ) where the second argument is a map of keys to set and their respective values.

Implementation Brief

  • Create a new datastore in assets/js/googlesitekit/datastore/forms that registers a new form data store, under 'core/forms'.
  • Create a assets/js/googlesitekit-forms.js that registers the core/forms store on the default registry.
  • Add a googlesitekit-forms asset in Assets.php, similar to googlesitekit-api, googlesitekit-data, etc. that would load the core/form datastore into the default registry.
  • Add a selector: getValue( formName, key ). This should return the value stored in the state[ formName ][ key]; undefined if the formName or key doesn’t exist.
  • Add an action: setValues( formName, { key: value } ) where the second argument is a map of keys to set and their respective values. If the specified formName doesn’t exist; it should be created.

QA Brief

  • Since this is an engineering-only feature for now, specific QA isn’t really needed.

Changelog entry

  • Introduce core/forms datastore to manage form state.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tofumattcommented, May 11, 2020

Sounds good; I’ve updated the IB with your suggestions, with one exception: I don’t think the extra setValue function provides any extra value. The functionality from setValue( 'foo', 'bar' ) is already present in setValues({ foo: 'bar' }), but the latter is more extensible if one wants to add more items.

I don’t think there’s much benefit in having the single-variable one, especially if we’re the only ones using this API for now. But it’s an extra API to maintain without much benefit, so I’d prefer not to add it. (It is easy, but it’s also not super-useful in my opinion.)

0reactions
ryanwelchercommented, May 27, 2020

Looks good to me! QA ✅

Read more comments on GitHub >

github_iconTop Results From Across the Web

Forms and Fields in ASP .NET Core | Wake Up And Code!
F is for Forms (and Fields); Tag Helpers for HTML form elements ... You can add additional server-side attributes within the <form> tag...
Read more >
tallence/core-forms: A simple and lean formeditor for ... - GitHub
Core Forms. Core Forms is a simple and lean extension for the CoreMedia CMS. Build simple forms in the CoreMedia Studio by your...
Read more >
Django Tutorial Part 9: Working with forms - MDN Web Docs
In this tutorial, we're going to show you a few of the ways you can create and work with forms, and in particular,...
Read more >
Core Forms HCF-AS Core Buildup - Henry Schein Dental
Shop Henry Schein Dental for Core Forms HCF-AS Core Buildup. Browse our full selection of products and order online.
Read more >
Forms - Rasa
Define a form by adding it to the forms section in your domain. The name of the form is also the name of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found