#State management issues

1 messages · Page 1 of 1 (latest)

delicate crater
#

Hey everyone, trying to create a template to build a CV and im now coming to a roadblock and I can't figure out what the issue is. I have a add_skills function which fills a state dict with topics and individual skills.
Somehow, some topics (after calling add_skills multiple times with different array of "learned_skills") are getting lost.

Example of a learned_skill array:

learned_skills: (
        (
          "category": (
            "de": "Cybersecurity",
            "en": "Cybersecurity"
          ),
          "values": (
            "de": ("Penetration Testing", "Reverse Engineering", "Web Security", "Cryptography", "Forensics", "Binary Exploitation"),
            "en": ("Penetration Testing", "Reverse Engineering", "Web Security", "Cryptography", "Forensics", "Binary Exploitation")
          )
        ),
      )

I would add this to the state with add_skills(dict.learned_skills) where dict is the individual "experience". From testing i can see that the array is being loaded in correctly. However in this case, after "adding" the following the topics "Technologies" and "Programming-/Scripting-Languages" do not make it to the final render function

learned_skills: ( 
        (
          "category": ( 
              "de": "Programmier-/Skripting-Sprachen", 
              "en": "Programming/Scripting Languages"
          ),
          "values": (
            "de": ("Python", "C", "C++", "Java", "JavaScript", "Bash", "HTML/CSS", "LaTeX"),
            "en": ("Python", "C", "C++", "Java", "JavaScript", "Bash", "HTML/CSS", "LaTeX")
          ),
        ),
        (
          "category": ( 
              "de": "Technologien", 
              "en": "Technologies"
          ),
          "values":  (
            "de": ("Docker", "Git", "SQL", "Excel", "Word", "Powerpoint", "Qiskit", "Ghidra", "Tigress"),
            "en": ("Docker", "Git", "SQL", "Excel", "Word", "Powerpoint", "Qiskit", "Ghidra", "Tigress"),
          )
        ),
        (
          "category": ( 
              "de": "Management", 
              "en": "Management"
          ),
          "values":  (
            "de": ("Risikomanagement", "Qualitätsmanagement", "Projektmanagement"),
            "en": ("Risk Management", "Quality Management", "Project Management")
            )
         ),
        (
          "category": ( 
              "de": "Betriebssysteme", 
              "en": "Operating Systems"
          ),
          "values":  (
            "de": ("Windows", "BSD (FreeBSD, OpenBSD)", "Debian-basierte Linux"),
            "en": ("Windows", "BSD (FreeBSD, OpenBSD)", "Debian-based Linux")
          )
        )
    )
#let add_skills(array) = {
  context{
    for category in array {
      let values = category.at("values").at(text.lang, default: ()) 
      
      let topic = category.at("category").at(text.lang)
    
  
      let skills = skills_state.get()
      
      let dict_items = values

      let existing_items = skills.at(topic, default: ())
      
      existing_items.push(dict_items)
      
      existing_items = existing_items.flatten()

      let new_items = existing_items.dedup()
      
      skills.insert(topic, new_items)
        
          
      skills_state.update(skills)
    
    }
  }
}

My render function looks as follows:


#let render-skills() ={
  context{
  let skills = skills_state.get()
   
    if(skills != none and skills != () and skills != "" and skills != "none") {
    let topics = skills.keys()
    topics = topics.sorted() // Sort topics alphabetically
    for topic in topics {
      if(topic != "PLACEHOLDER") [
        #let skills_items = skills.at(topic)
        - *#topic:* #skills_items.join(", ") \
      ] 
    }
  }
  }
}

And the function to render a specific section of the CV would look like this:

#
#let work(
  title: "",
  dates: "",
  company: (),
  location: "",
  description: (),
  learned_skills: ()
) = {
  let main_company = company.at(0)
  let company_extra = company.slice(1, company.len())

  company = [#emph(main_company), #text(9pt, company_extra.join(", "))]
  

  if(description != "") {
    generic-two-by-two-with-description(
      top-left: strong(title),
      top-right: dates,
      bottom-left: company,
      bottom-right: location,
      description: description,
    )
  } else {
    generic-two-by-two(
      top-left: strong(title),
      top-right: dates,
      bottom-left: company,
      bottom-right: location,
    )
  }

  add_skills(learned_skills)
}
#

State management issues

#

#let skills_state = state("skills", (:))

half jacinth
#

I think this answer applies directly to your situation: https://forum.typst.app/t/why-is-state-final-not-final/1483/2?u=sillyfreak

Typst Forum

If you look closely, you’ll see that Typst is actually warning you about a problem with your document: Layout did not converge within 5 attempts This problem is hard to debug in general, but here the source of the problem is fairly easy to recognize and fix: your state updates are structured like context { x = foo.get() .. foo.updat...