Forráskód Böngészése

Use lenses in all art deco code

jherve 1 éve
szülő
commit
71b5dbe086
3 módosított fájl, 49 hozzáadás és 61 törlés
  1. 7 37
      src/LinkedIn/ArtDeco.purs
  2. 21 12
      src/LinkedIn/ArtDecoCard.purs
  3. 21 12
      src/LinkedIn/ArtDecoTab.purs

+ 7 - 37
src/LinkedIn/ArtDeco.purs

@@ -4,12 +4,9 @@ import Prelude
 
 import Data.Foldable (class Foldable, foldMap, foldlDefault, foldrDefault)
 import Data.Generic.Rep (class Generic)
-import Data.Lens (Lens', Traversal', lens', toListOf, traversed, view)
+import Data.Lens (Lens', Traversal', lens', traversed)
 import Data.Lens.Record (prop)
-import Data.List (List)
-import Data.List as L
 import Data.List.NonEmpty (NonEmptyList)
-import Data.List.NonEmpty as NEL
 import Data.Maybe (Maybe)
 import Data.Show.Generic (genericShow)
 import Data.Traversable (class Traversable, sequence, traverseDefault)
@@ -173,19 +170,6 @@ queryArtDecoPvsEntity n = do
   center <- subQueryOne queryArtDecoCenter ":scope > div.display-flex" n
   pure $ ArtDecoPvsEntity {side: unit, center}
 
-toHeaderBold ∷ forall a. ArtDecoPvsEntity a → a
-toHeaderBold = view $ _pvs_to_header <<< prop (Proxy :: Proxy "bold")
-
-toHeaderNormal ∷ forall a. ArtDecoPvsEntity a → Maybe (a)
-toHeaderNormal (ArtDecoPvsEntity {
-  center: ArtDecoCenter { header: ArtDecoCenterHeader { normal }}
-}) = normal
-
-toHeaderLight ∷ forall a. ArtDecoPvsEntity a → Maybe (NonEmptyList a)
-toHeaderLight (ArtDecoPvsEntity {
-  center: ArtDecoCenter { header: ArtDecoCenterHeader { light }}
-}) = light
-
 _pvs_entity :: forall a. Lens' (ArtDecoPvsEntity a) { center ∷ ArtDecoCenter a , side ∷ Unit }
 _pvs_entity = lens'
   \(ArtDecoPvsEntity pvs) -> Tuple pvs \pvs' -> ArtDecoPvsEntity pvs'
@@ -219,25 +203,11 @@ _pvs_to_subcomponents = _pvs_entity
   <<< traversed
   <<< _sub_component
 
-toHeaderBold' ∷ ∀ a. ArtDecoPvsEntity a → a
-toHeaderBold' = view $ _pvs_to_header <<< prop (Proxy :: Proxy "bold")
+_pvs_to_header_bold :: forall a. Lens' (ArtDecoPvsEntity a) a
+_pvs_to_header_bold = _pvs_to_header <<< prop (Proxy :: Proxy "bold")
 
-toHeaderNormal' ∷ ∀ a. ArtDecoPvsEntity a → Maybe a
-toHeaderNormal' = view $ _pvs_to_header <<< prop (Proxy :: Proxy "normal")
-
-toHeaderLight' ∷ ∀ a. ArtDecoPvsEntity a → Maybe (NonEmptyList a)
-toHeaderLight' = view $ _pvs_to_header <<< prop (Proxy :: Proxy "light")
-
-toCenterContent' ∷ ∀ a. ArtDecoPvsEntity a → List (Maybe a)
-toCenterContent' = toListOf $ _pvs_entity
-  <<< prop (Proxy :: Proxy "center")
-  <<< _center
-  <<< prop (Proxy :: Proxy "content")
-  <<< _content
-  <<< traversed
-  <<< _sub_component
+_pvs_to_header_normal :: forall a. Lens' (ArtDecoPvsEntity a) (Maybe a)
+_pvs_to_header_normal = _pvs_to_header <<< prop (Proxy :: Proxy "normal")
 
-toCenterContent ∷ forall a. ArtDecoPvsEntity a → List a
-toCenterContent (ArtDecoPvsEntity {
-  center: ArtDecoCenter { content: ArtDecoCenterContent subComponents }
-}) = NEL.catMaybes $ map (\(ArtDecoPvsEntitySubComponent c) -> c) subComponents
+_pvs_to_header_light :: forall a. Lens' (ArtDecoPvsEntity a) (Maybe (NonEmptyList a))
+_pvs_to_header_light = _pvs_to_header <<< prop (Proxy :: Proxy "light")

+ 21 - 12
src/LinkedIn/ArtDecoCard.purs

@@ -4,14 +4,18 @@ import Prelude
 
 import Data.Foldable (class Foldable, foldMap, foldlDefault, foldrDefault)
 import Data.Generic.Rep (class Generic)
+import Data.Lens (Lens', lens', toListOf, view)
+import Data.Lens.Record (prop)
 import Data.List (List)
+import Data.List as L
 import Data.List.Types (NonEmptyList)
 import Data.Maybe (Maybe)
 import Data.Show.Generic (genericShow)
 import Data.Traversable (class Traversable, sequence, traverseDefault)
-import LinkedIn.ArtDeco (ArtDecoPvsEntity, queryArtDecoPvsEntity)
-import LinkedIn.ArtDeco as AD
+import Data.Tuple (Tuple(..))
+import LinkedIn.ArtDeco (ArtDecoPvsEntity, _pvs_to_header_bold, _pvs_to_header_light, _pvs_to_header_normal, _pvs_to_subcomponents, queryArtDecoPvsEntity)
 import LinkedIn.QueryRunner (QueryRunner, subQueryOne)
+import Type.Proxy (Proxy(..))
 import Web.DOM (Node)
 
 
@@ -43,17 +47,22 @@ queryArtDecoCard n = do
   pvs_entity <- subQueryOne queryArtDecoPvsEntity ":scope div.pvs-entity--padded" n
   pure $ ArtDecoCardElement {pvs_entity}
 
-toCenterContent ∷ forall a. ArtDecoCardElement a → List a
-toCenterContent = toPvsEntity >>> AD.toCenterContent
+toHeaderBold ∷ ∀ a. ArtDecoCardElement a → a
+toHeaderBold = view $ _card_to_pvs_entity <<< _pvs_to_header_bold
 
-toHeaderBold ∷ forall a. ArtDecoCardElement a → a
-toHeaderBold = toPvsEntity >>> AD.toHeaderBold
+toHeaderNormal ∷ ∀ a. ArtDecoCardElement a → Maybe a
+toHeaderNormal = view $ _card_to_pvs_entity <<< _pvs_to_header_normal
 
-toHeaderLight ∷ forall a.  ArtDecoCardElement a → Maybe (NonEmptyList a)
-toHeaderLight = toPvsEntity >>> AD.toHeaderLight
+toHeaderLight ∷ ∀ a. ArtDecoCardElement a → Maybe (NonEmptyList a)
+toHeaderLight = view $ _card_to_pvs_entity <<< _pvs_to_header_light
 
-toHeaderNormal ∷ forall a. ArtDecoCardElement a → Maybe a
-toHeaderNormal = toPvsEntity >>> AD.toHeaderNormal
+toCenterContent ∷ ∀ a. ArtDecoCardElement a → List a
+toCenterContent c = L.catMaybes $ toContent c
+  where
+    toContent = toListOf $ _card_to_pvs_entity <<< _pvs_to_subcomponents
 
-toPvsEntity ∷ forall a. ArtDecoCardElement a → ArtDecoPvsEntity a
-toPvsEntity (ArtDecoCardElement { pvs_entity }) = pvs_entity
+_card :: forall a. Lens' (ArtDecoCardElement a) { pvs_entity ∷ ArtDecoPvsEntity a }
+_card = lens' \(ArtDecoCardElement c) -> Tuple c \c' -> ArtDecoCardElement c'
+
+_card_to_pvs_entity :: forall a. Lens' (ArtDecoCardElement a) (ArtDecoPvsEntity a)
+_card_to_pvs_entity = _card <<< prop (Proxy :: Proxy "pvs_entity")

+ 21 - 12
src/LinkedIn/ArtDecoTab.purs

@@ -4,14 +4,18 @@ import Prelude
 
 import Data.Foldable (class Foldable, foldMap, foldlDefault, foldrDefault)
 import Data.Generic.Rep (class Generic)
+import Data.Lens (Lens', lens', toListOf, view)
+import Data.Lens.Record (prop)
 import Data.List (List)
+import Data.List as L
 import Data.List.Types (NonEmptyList)
 import Data.Maybe (Maybe)
 import Data.Show.Generic (genericShow)
 import Data.Traversable (class Traversable, sequence, traverseDefault)
-import LinkedIn.ArtDeco (ArtDecoPvsEntity, queryArtDecoPvsEntity)
-import LinkedIn.ArtDeco as AD
+import Data.Tuple (Tuple(..))
+import LinkedIn.ArtDeco (ArtDecoPvsEntity, _pvs_to_header_bold, _pvs_to_header_light, _pvs_to_header_normal, _pvs_to_subcomponents, queryArtDecoPvsEntity)
 import LinkedIn.QueryRunner (QueryRunner, subQueryOne)
+import Type.Proxy (Proxy(..))
 import Web.DOM (Node)
 
 
@@ -43,17 +47,22 @@ queryArtDecoTab n = do
   pvs_entity <- subQueryOne queryArtDecoPvsEntity ":scope div.pvs-entity--padded" n
   pure $ ArtDecoTabElement {pvs_entity}
 
-toCenterContent ∷ forall a. ArtDecoTabElement a → List a
-toCenterContent = toPvsEntity >>> AD.toCenterContent
+toHeaderBold ∷ ∀ a. ArtDecoTabElement a → a
+toHeaderBold = view $ _tab_to_pvs_entity <<< _pvs_to_header_bold
 
-toHeaderBold ∷ forall a. ArtDecoTabElement a → a
-toHeaderBold = toPvsEntity >>> AD.toHeaderBold
+toHeaderNormal ∷ ∀ a. ArtDecoTabElement a → Maybe a
+toHeaderNormal = view $ _tab_to_pvs_entity <<< _pvs_to_header_normal
 
-toHeaderLight ∷ forall a. ArtDecoTabElement a → Maybe (NonEmptyList a)
-toHeaderLight = toPvsEntity >>> AD.toHeaderLight
+toHeaderLight ∷  a. ArtDecoTabElement a → Maybe (NonEmptyList a)
+toHeaderLight = view $ _tab_to_pvs_entity <<< _pvs_to_header_light
 
-toHeaderNormal ∷ forall a. ArtDecoTabElement a → Maybe a
-toHeaderNormal = toPvsEntity >>> AD.toHeaderNormal
+toCenterContent ∷ ∀ a. ArtDecoTabElement a → List a
+toCenterContent c = L.catMaybes $ toContent c
+  where
+    toContent = toListOf $ _tab_to_pvs_entity <<< _pvs_to_subcomponents
 
-toPvsEntity ∷ forall a. ArtDecoTabElement a → ArtDecoPvsEntity a
-toPvsEntity (ArtDecoTabElement { pvs_entity }) = pvs_entity
+_tab :: forall a. Lens' (ArtDecoTabElement a) { pvs_entity ∷ ArtDecoPvsEntity a }
+_tab = lens' \(ArtDecoTabElement t) -> Tuple t \t' -> ArtDecoTabElement t'
+
+_tab_to_pvs_entity :: forall a. Lens' (ArtDecoTabElement a) (ArtDecoPvsEntity a)
+_tab_to_pvs_entity = _tab <<< prop (Proxy :: Proxy "pvs_entity")