or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
Re-factoring Papad angular front-end application
Background
Papad is a web annotation client application, at this time focusing on the audio annotations.
Say how we have HTML (Hyper Text Markup Language) pages, and links to these pages that we can refer in other pages, would also be nice if the web supported, what we call Hyper Media linking, so that one can refer to a section in the audio in specific contexts.
(Discuss how much of this background should be here, or be linked to other docs)
Features
The current features of this application is
While the above is a abstract definition of the features, we'll specifically look into our current implementation, alpha version is a angular application.
Why angular
Well, the answer is these modern frameworks are all over the place. It's so easy to get started with so many online resources, but sadly all of them are "Hello World" programs with very less real world use cases. The developer will find herself doing lot more learning while implementing a real app. and ofworks all these jargons that's running around two way data binding, reactive programming, component architecture, and other jazz is supposed to make the developer's life easy. But i'll tell you what happens in reality in a bit.
Papad's current directories looks like this, and the very first look at this, one will have a question about what is
papad
folder. That's the component that's handling the home page in the app, look at demo hereDemo of the papad component
Looking at the above home page, we can visually see 3 main regions,
And the
papad.component.ts
is handling the items 2 and 3, but there is quite a bit going on here between those two sections.Just like that
papad.component.ts
is now a 200 lines TS file, the class defines about 12 variables.Like i said earlier re. Angular's features, all that is given up in our current implementation, and the developer's life got no better. will discuss one specific problem to demonstrate this.
Why re-factor - Tag filter usecase
The Tags cloud you saw in the demo, is a small example and below is a list of issues that came up in our issue tracker during testing. There was always issues starting with how to filter data, where to save state, how to keep it RestFul.
selectList()
is a method inpapad.component.ts
that is called when a tag is clicked. below is the code, but don't bother going through, i can explain what is happening.this.collectTags
in the below code.array.splice
and update cards collectionwhile doing all that, say another developer who wants to fix something in this code, doing
CTRL-F
for all the variables and so on, and debugging just got harder. we were probably better of with jQuery code.Expand here to see, sample tag click handler from
papad.component.ts
The re-factoring story
So, let's get back to basics here. Ofcourse i had to see a couple of videos and found this youtube channel really helpful, kudvenkat on youtube as some real time example and scenarios are discussed.
Remember i said there are 3 visual sections in the demo, yes, we need to break it down into it's fundamental parts.
Re-structuring components
My new folder structure is like this now, where i've created 5 components instead of the
papad component
, so much to break the 200 lines TS file. But it's atleast better, coz i don't have to do find in file, but i have to do find in folder.Let's look at our Tag component, at
tag-component.ts
which is a single tag, which is a<span>
HTML element. It has two properties,value
andselected
which is inherited from it's parent, and declares a event that it emits when thetag.selected
property changes, so the parent can update other components.more TBA
Plugging the Router
Plumbing for event bubbling
Is there any better way?
Conclusion