24. ● List operations for a given service
● Register operations for a given service
Browse Operations
25. What are our
steps?
● Structure
● Loading Components
● Code Consistency
● Testing
● Extending
26. Definitions
Component Encapsulates an AngularJS feature, defined as a unit of work that exposes a UI segment
or common utility functions exposed as a service. Manifestation of a feature
Feature Logical unit, a feature is implemented as a component (feature is the thought,
component is the representation)
Module In the context of AngularJS, a module can represent a single component or a collection
of components that provide a business function
29. Function based structure
● Foo and bar features
● Separated by AngularJS
functionality
● Consistent naming
30. Function based structure
● Foo and bar features
● Separated by AngularJS
functionality
● Consistent naming
Challenging to scale past 4 or 5 modules
31. Problems with function based structures
● Dependent on implied coding conventions
○ Must name each feature file consistently
○ Requires concise naming up front
● Features exist only as a function of AngularJS
● Determining test coverage of an independent feature is challenging
33. Structuring components
LIFT [STYLE Y140]
Locating our code is easy
Identify code at a glance
Flat structure as long as we can
Try to stay DRY (Don’t Repeat Yourself) or T-DRY
34. Feature based structure
● Foo and bar modules
● Feature based
● Flat structure
● No reliance on file names
● Consistent with node
projects
35. Structuring Components
app
application main component
browse
service browse logic
operations
operations browse logic
registry
provider to register services
api-foo
mock service
36. Structuring Components
● Flat directory structure
● Names represent feature
● Nothing angular so far
● No file name dependency
● Identifies content
● Features encapsulated
40. Loading Components
● index.html merge conflict when working in distributed
environments
● declares the universe of scripts, not specifically what your
application is actually using
● does not tie back to components
● duplicated when unit testing using tools like Karma
42. Loading Components
● Reduce merge conflicts on index.html
● Use the component structure already present in our app
● Declare our dependencies
● Have it done automatically
○ Let the build tools manage it!!
What do we want?
51. Code Consistency
[Y001] - One component per file
[Y020] - Avoid naming collisions
[Y024] - Use named instead of anonymous functions
Just a small list, implement the John Papa code style
guidelines
52. [Y001] - One component per file
Code Consistency
● Export a single AngularJS
function
Benefits
● Small focused functionality
● Maintenance / readability
● Debugging
● Portability
53. [Y001] - One component per file
Code Consistency
● Export a single AngularJS
function
Benefits
● Small focused functionality
● Maintenance / readability
● Debugging
● Portability
56. Testing Components
Test Configuration
● Single import, same as index.html
● Components synchronized (app
and unit test)
Note
Bring your own test tools, doesn’t have
to be Karma or Jasmine
61. Extending
Packaging
● Pull in modules from local and remote
repositories (i.e. artifactory)
● Independent testing as modules
● Support distributed development
● Independent versioning
Benefits