22.7. Revising Searching

Currently the search feature is accomplished with the following classes:

  • CategorySearchEvent

  • KeyWordSearchEvent

  • ClearSearchResultsEvent

  • CategorySearchDelegate

  • KeyWordSearchDelegate

  • CategorySearchCommand

  • ClearSearchResultsCommand

  • KeyWordSearchCommand

The CategorySearchEvent, KeyWordSearchEvent, and ClearSearchResultsEvent classes will become types of the SearchEvent class. Again, since these events currently expect different types of data to be passed, you will have to construct the event to allow for multiple data types.

The CategorySearchDelegate and the KeyWordSearchDelegate will be consolidated into a SearchDelegate class. However, in this case the functions that exist on both delegates are named search, and they will have to be renamed when they are moved to the new delegate.

The execute functions of the CategorySearchCommand and KeyWordSearchCommand commands will have to be updated to cast the data passed by the SearchEvent and to use the new SearchDelegate.

The ClearSearchResultsCommand does not use any data passed from the event, nor does it use a delegate, so this class can remain as it is.

Start by creating the new search event. In the com.FlexBlog.events package create a new event class named SearchEvent. Edit the class to match the following:

package com.FlexBlog.events { import com.adobe.cairngorm.control.CairngormEvent; public class SearchEvent extends CairngormEvent { public static const KEYWORD_SEARCH:String = 'keywordSearchEvent'; public static ...

Get Professional Cairngorm™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.