Skip to content

Commit

Permalink
refactor(src): readability improvements (#193)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Russell <[email protected]>

Signed-off-by: Ryan Russell <[email protected]>
  • Loading branch information
ryanrussell authored Sep 24, 2022
1 parent a0328fc commit 2309c5c
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions packages/perseus/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async fn gen_state_for_path(
global_state: &Option<String>,
) -> Result<(), ServerError> {
let template_path = template.get_path();
// If needed, we'll contruct a full path that's URL encoded so we can easily
// If needed, we'll construct a full path that's URL encoded so we can easily
// save it as a file
let full_path_without_locale = match template.uses_build_paths() {
true => format!("{}/{}", &template_path, path),
Expand Down Expand Up @@ -130,7 +130,7 @@ async fn gen_state_for_path(
let initial_state = template
.get_build_state(full_path_without_locale.clone(), translator.get_locale())
.await?;
// Write that intial state to a static JSON file
// Write that initial state to a static JSON file
mutable_store
.write(
&format!("static/{}.json", full_path_encoded),
Expand Down Expand Up @@ -167,7 +167,7 @@ async fn gen_state_for_path(
let initial_state = template
.get_build_state(full_path_without_locale.clone(), translator.get_locale())
.await?;
// Write that intial state to a static JSON file
// Write that initial state to a static JSON file
immutable_store
.write(
&format!("static/{}.json", full_path_encoded),
Expand Down
4 changes: 2 additions & 2 deletions packages/perseus/src/i18n/translations_manager.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file contains the logic for a universal interface to fecth `Translator`
// This file contains the logic for a universal interface to fetch `Translator`
// instances for given locales At simplest, this is just a filesystem interface,
// but it might be something like a database in production This has its own
// error management logic because the user may implement it separately
Expand Down Expand Up @@ -146,7 +146,7 @@ impl FsTranslationsManager {
let cached_translations_kv_vec = join_all(futs).await;
manager.cached_translations = cached_translations_kv_vec.iter().cloned().collect();
// We only declare the locales that are being cached after getting translations
// becuase otherwise those getters would be using undefined caches
// because otherwise those getters would be using undefined caches
manager.cached_locales = locales_to_cache;

manager
Expand Down
4 changes: 2 additions & 2 deletions packages/perseus/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
format!("<!DOCTYPE html>\n{}", self.index_view)
}
/// Gets an HTML shell from an index view string. This is broken out so that
/// it can be executed after the app has been built (which requries getting
/// it can be executed after the app has been built (which requires getting
/// the translations manager, consuming `self`). As inconvenient as this
/// is, it's necessitated, otherwise exporting would try to access the built
/// app before it had actually been built.
Expand All @@ -582,7 +582,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
let mut html_shell = HtmlShell::new(
index_view_str,
root,
// TODO Handle this properly (good enough for now because that's what we weere already
// TODO Handle this properly (good enough for now because that's what we were already
// doing)
&get_render_cfg(immutable_store)
.await
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub mod state;
/// [`ImmutableStore`] and [`MutableStore`] for details.
pub mod stores;
/// Utilities for working with templates and state generation. This is by far
/// the module you'll procably access the most.
/// the module you'll probably access the most.
pub mod template;
/// General utilities that may be useful while building Perseus apps.
pub mod utils;
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ macro_rules! define_app {
// We need the filesystem here, and we don't need on it in the browser
// We can't modify `app` if this is all in a block, so we compromise a bit
let index_html = if cfg!(target_arch = "wasm32") {
// In the browser, this would turn into using the hardocded default, but we don't need the index view there anyway
// In the browser, this would turn into using the hardcoded default, but we don't need the index view there anyway
::std::result::Result::Err(::std::io::Error::from(::std::io::ErrorKind::NotFound))
} else {
::std::fs::read_to_string("../index.html")
Expand Down
6 changes: 3 additions & 3 deletions packages/perseus/src/plugins/plugins_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type PluginDataMap = HashMap<String, Box<dyn Any + Send>>;

/// A representation of all the plugins used by an app.
///
/// Due to the sheer number and compexity of nested fields, this is best
/// Due to the sheer number and complexity of nested fields, this is best
/// transferred in an `Rc`, which unfortunately results in double indirection
/// for runner functions.
pub struct Plugins<G: Html> {
Expand Down Expand Up @@ -49,7 +49,7 @@ impl<G: Html> Plugins<G> {
/// error if one has, noting the conflict explicitly in the error message.
/// This can only register plugins that run exclusively on the
/// server-side (including tinker-time and the build process).
// We allow unusued variables and the like for linting because otherwise any
// We allow unused variables and the like for linting because otherwise any
// errors in Wasm compilation will show these up, which is annoying
pub fn plugin<D: Any + Send>(
#[cfg_attr(target_arch = "wasm32", allow(unused_mut))] mut self,
Expand Down Expand Up @@ -88,7 +88,7 @@ impl<G: Html> Plugins<G> {
}
/// The same as `.plugin()`, but registers a plugin that can run on the
/// client-side. This is deliberately separated out to make conditional
/// compilation feasible and to emphasize to users what's incrasing their
/// compilation feasible and to emphasize to users what's increasing their
/// bundle sizes. Note that this should also be used for plugins that
/// run on both the client and server.
pub fn plugin_with_client_privilege<D: Any + Send>(
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/router/match_route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn get_template_for_path<G: Html>(

/// A version of `get_template_for_path` that accepts an `ArcTemplateMap<G>`.
/// This is used by `match_route_atomic`, which should be used in scenarios in
/// which the template map needs to be passed betgween threads.
/// which the template map needs to be passed between threads.
///
/// Warning: this returns a `&Template<G>` rather than a `Rc<Template<G>>`, and
/// thus should only be used independently of the rest of Perseus (through
Expand Down
4 changes: 2 additions & 2 deletions packages/perseus/src/router/router_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use sycamore_router::{HistoryIntegration, RouterBase};
use web_sys::Element;

// We don't want to bring in a styling library, so we do this the old-fashioned
// way! We're particualrly comprehensive with these because the user could
// way! We're particularly comprehensive with these because the user could
// *potentially* stuff things up with global rules https://medium.com/@jessebeach/beware-smushed-off-screen-accessible-text-5952a4c2cbfe
const ROUTE_ANNOUNCER_STYLES: &str = r#"
margin: -1px;
Expand Down Expand Up @@ -96,7 +96,7 @@ async fn get_view(
RouteVerdict::LocaleDetection(path) => {
let dest = detect_locale(path.clone(), &locales);
// Since this is only for subsequent loads, we know the router is instantiated
// This shouldn't be a replacement navigation, since the user has deliberatley
// This shouldn't be a replacement navigation, since the user has deliberately
// navigated here
sycamore_router::navigate(&dest);
View::empty()
Expand Down
4 changes: 2 additions & 2 deletions packages/perseus/src/server/html_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn escape_page_data(data: &str) -> String {
/// plugins.
#[derive(Clone, Debug)]
pub struct HtmlShell {
/// The actual shell content, on whcih interpolations will be performed.
/// The actual shell content, on which interpolations will be performed.
pub shell: String,
/// Additional contents of the head before the interpolation boundary.
pub head_before_boundary: Vec<String>,
Expand All @@ -29,7 +29,7 @@ pub struct HtmlShell {
/// Additional contents of the head after the interpolation boundary. These
/// will be wiped out after a page transition.
pub head_after_boundary: Vec<String>,
/// Scripts to be interpolated after the interpolation bounary. These will
/// Scripts to be interpolated after the interpolation boundary. These will
/// be wiped out after a page transition.
pub scripts_after_boundary: Vec<String>,
/// Content to be interpolated into the body of the shell.
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/server/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ async fn should_revalidate(
req: Request,
) -> Result<bool, ServerError> {
let mut should_revalidate = false;
// If it revalidates after a certain period of time, we needd to check that
// If it revalidates after a certain period of time, we need to check that
// BEFORE the custom logic
if template.revalidates_with_time() {
// Get the time when it should revalidate (RFC 3339)
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/state/freeze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub enum PageThawPrefs {
/// Includes all pages in the app, making frozen state always override state
/// that's already been initialized.
IncludeAll,
/// Exludes the attached pages by their URLs (with no leading `/`). Pages
/// Excludes the attached pages by their URLs (with no leading `/`). Pages
/// listed here will prioritize active state over frozen state as usual, and
/// any pages not listed here will prioritize frozen state.
/// `Exclude(Vec::new())` is equivalent to `IncludeAll`.
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/state/freeze_idb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub enum IdbError {
#[source]
source: RexieError,
},
#[error("an error occured while trying to set a new value")]
#[error("an error occurred while trying to set a new value")]
SetError {
#[source]
source: RexieError,
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/state/live_reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub(crate) fn connect_to_reload_server(live_reload_tx: Sender<()>) {
Ok(ws) => ws,
Err(err) => return log(&format!("Connection failed: {:?}.", err)),
};
// This is apparently more efficient for small bianry messages
// This is apparently more efficient for small binary messages
ws.set_binary_type(web_sys::BinaryType::Arraybuffer);

// Set up a message handler
Expand Down
12 changes: 6 additions & 6 deletions packages/perseus/src/template/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub type GetBuildStateFn = Box<dyn GetBuildStateFnType + Send + Sync>;
/// The type of functions that get request state.
#[cfg(not(target_arch = "wasm32"))]
pub type GetRequestStateFn = Box<dyn GetRequestStateFnType + Send + Sync>;
/// The type of functions that check if a template sghould revalidate.
/// The type of functions that check if a template should revalidate.
#[cfg(not(target_arch = "wasm32"))]
pub type ShouldRevalidateFn = Box<dyn ShouldRevalidateFnType + Send + Sync>;
/// The type of functions that amalgamate build and request states.
Expand Down Expand Up @@ -149,7 +149,7 @@ pub struct Template<G: Html> {
/// A function that will be used to populate the document's `<head>` with
/// metadata such as the title. This will be passed state in
/// the same way as `template`, but will always be rendered to a string,
/// whcih will then be interpolated directly into the `<head>`,
/// which will then be interpolated directly into the `<head>`,
/// so reactivity here will not work!
#[cfg(not(target_arch = "wasm32"))]
head: TemplateFn<SsrNode>,
Expand All @@ -170,10 +170,10 @@ pub struct Template<G: Html> {
/// prerendered and cached in production. This allows you to
/// have potentially billions of templates and retain a super-fast build
/// process. The first user will have an ever-so-slightly slower
/// experience, and everyone else gets the beneftis afterwards. This
/// experience, and everyone else gets the benefits afterwards. This
/// requires `get_build_paths`. Note that the template root will NOT
/// be rendered on demand, and must be explicitly defined if it's wanted. It
/// can uuse a different template.
/// can use a different template.
#[cfg(not(target_arch = "wasm32"))]
incremental_generation: bool,
/// A function that gets the initial state to use to prerender the template
Expand Down Expand Up @@ -331,7 +331,7 @@ impl<G: Html> Template<G> {
/// Gets the initial state for a template. This needs to be passed the full
/// path of the template, which may be one of those generated by
/// `.get_build_paths()`. This also needs the locale being rendered to so
/// that more compelx applications like custom documentation systems can
/// that more complex applications like custom documentation systems can
/// be enabled.
#[cfg(not(target_arch = "wasm32"))]
pub async fn get_build_state(
Expand Down Expand Up @@ -518,7 +518,7 @@ impl<G: Html> Template<G> {
self.get_build_state.is_some()
}
/// Checks if this template has custom logic to amalgamate build and
/// reqquest states if both are generated.
/// request states if both are generated.
#[cfg(not(target_arch = "wasm32"))]
pub fn can_amalgamate_states(&self) -> bool {
self.amalgamate_states.is_some()
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/translator/fluent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl FluentTranslator {
pub fn url(&self, url: &str) -> String {
format!("{}{}", self.locale, url)
}
/// Gets the locale for which this instancce is configured.
/// Gets the locale for which this instance is configured.
pub fn get_locale(&self) -> String {
self.locale.clone()
}
Expand Down
6 changes: 3 additions & 3 deletions packages/perseus/src/translator/lightweight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub const LIGHTWEIGHT_TRANSLATOR_FILE_EXT: &str = "json";
/// like pluralization with this system, you should use multiple separate
/// translation IDs.
///
/// This system supports variants only in the msot basic way: you could create
/// This system supports variants only in the most basic way: you could create
/// multiple 'sub-ids' on ID `x` by having one ID called `x.y` and another
/// called `x.z`, etc., but the system doesn't particularly care, unlike Fluent,
/// which explicitly handles these cases.
Expand Down Expand Up @@ -64,7 +64,7 @@ impl LightweightTranslator {
pub fn url(&self, url: &str) -> String {
format!("{}{}", self.locale, url)
}
/// Gets the locale for which this instancce is configured.
/// Gets the locale for which this instance is configured.
pub fn get_locale(&self) -> String {
self.locale.clone()
}
Expand Down Expand Up @@ -121,7 +121,7 @@ impl LightweightTranslator {
}

/// A *very* simple argument interpolation system based on a `HashMap`. Any more
/// complex functionality shoudl use `translator-fluent` instead.
/// complex functionality should use `translator-fluent` instead.
#[doc(hidden)]
#[allow(missing_debug_implementations)]
pub struct TranslationArgs(pub HashMap<String, String>);
Expand Down

0 comments on commit 2309c5c

Please sign in to comment.