Skip to content

Commit

Permalink
more :pure functions
Browse files Browse the repository at this point in the history
  • Loading branch information
joshtynjala committed Aug 9, 2023
1 parent f047b7f commit 963a4fb
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/feathers/controls/navigators/PageItem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class PageItem {
@since 1.0.0
**/
@:pure
public static function withClass(viewClass:Class<DisplayObject>):PageItem {
var item = new PageItem();
item.viewFactory = viewClass;
Expand All @@ -50,6 +51,7 @@ class PageItem {
@since 1.0.0
**/
@:pure
public static function withFunction(viewFunction:() -> DisplayObject):PageItem {
var item = new PageItem();
item.viewFactory = viewFunction;
Expand All @@ -62,6 +64,7 @@ class PageItem {
@since 1.0.0
**/
@:pure
public static function withDisplayObject(viewInstance:DisplayObject):PageItem {
var item = new PageItem();
item.viewFactory = viewInstance;
Expand All @@ -74,6 +77,7 @@ class PageItem {
@since 1.3.0
**/
@:pure
public static function withFactory(viewFactory:AbstractDisplayObjectFactory<Dynamic, DisplayObject>):PageItem {
var item = new PageItem();
item.viewFactory = viewFactory;
Expand Down
5 changes: 5 additions & 0 deletions src/feathers/controls/navigators/Route.hx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Route {
@since 1.0.0
**/
@:pure
public static function withClass<T:DisplayObject>(path:String, viewClass:Class<T>, ?actions:Map<String, RouterAction>,
?updateState:(view:T, state:RouteState) -> Void, ?saveData:(view:T) -> Dynamic):Route {
var item = new Route();
Expand All @@ -71,6 +72,7 @@ class Route {
@since 1.0.0
**/
@:pure
public static function withFunction<T:DisplayObject>(path:String, viewFunction:() -> T, ?actions:Map<String, RouterAction>,
?updateState:(view:T, state:RouteState) -> Void, ?saveData:(view:T) -> Dynamic):Route {
var item = new Route();
Expand All @@ -88,6 +90,7 @@ class Route {
@since 1.0.0
**/
@:pure
public static function withDisplayObject<T:DisplayObject>(path:String, viewInstance:T, ?actions:Map<String, RouterAction>,
?updateState:(view:T, state:RouteState) -> Void, ?saveData:(view:T) -> Dynamic):Route {
var item = new Route();
Expand All @@ -105,6 +108,7 @@ class Route {
@since 1.3.0
**/
@:pure
public static function withFactory<T:DisplayObject>(path:String, viewFactory:AbstractDisplayObjectFactory<T, DisplayObject>,
?actions:Map<String, RouterAction>, ?updateState:(view:T, state:RouteState) -> Void, ?saveData:(view:T) -> Dynamic):Route {
var item = new Route();
Expand All @@ -119,6 +123,7 @@ class Route {
/**
Creates a `Route` that redirects to a different path.
**/
@:pure
public static function withRedirect(path:String, redirectTo:String):Route {
var item = new Route();
item.path = path;
Expand Down
1 change: 1 addition & 0 deletions src/feathers/controls/navigators/RouterNavigator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ class Location {
@since 1.0.0
**/
@:pure
public static function fromString(value:String):Location {
var pathname = value;
var search = "";
Expand Down
4 changes: 4 additions & 0 deletions src/feathers/controls/navigators/StackItem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class StackItem {
@since 1.0.0
**/
@:pure
public static function withClass(id:String, viewClass:Class<DisplayObject>, ?actions:Map<String, StackAction>,
?returnHandlers:Map<String, (Dynamic, Dynamic) -> Void>, ?saveData:(view:Dynamic) -> Dynamic,
?restoreData:(view:Dynamic, data:Dynamic) -> Void):StackItem {
Expand All @@ -67,6 +68,7 @@ class StackItem {
@since 1.0.0
**/
@:pure
public static function withFunction(id:String, viewFunction:() -> DisplayObject, ?actions:Map<String, StackAction>,
?returnHandlers:Map<String, (Dynamic, Dynamic) -> Void>, ?saveData:(view:Dynamic) -> Dynamic,
?restoreData:(view:Dynamic, data:Dynamic) -> Void):StackItem {
Expand All @@ -86,6 +88,7 @@ class StackItem {
@since 1.0.0
**/
@:pure
public static function withDisplayObject(id:String, viewInstance:DisplayObject, ?actions:Map<String, StackAction>,
?returnHandlers:Map<String, (Dynamic, Dynamic) -> Void>, ?saveData:(view:Dynamic) -> Dynamic,
?restoreData:(view:Dynamic, data:Dynamic) -> Void):StackItem {
Expand All @@ -105,6 +108,7 @@ class StackItem {
@since 1.3.0
**/
@:pure
public static function withFactory(id:String, viewFactory:AbstractDisplayObjectFactory<Dynamic, DisplayObject>, ?actions:Map<String, StackAction>,
?returnHandlers:Map<String, (Dynamic, Dynamic) -> Void>, ?saveData:(view:Dynamic) -> Dynamic,
?restoreData:(view:Dynamic, data:Dynamic) -> Void):StackItem {
Expand Down
4 changes: 4 additions & 0 deletions src/feathers/controls/navigators/TabItem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class TabItem {
@since 1.0.0
**/
@:pure
public static function withClass(text:String, viewClass:Class<DisplayObject>):TabItem {
var item = new TabItem();
item.text = text;
Expand All @@ -52,6 +53,7 @@ class TabItem {
@since 1.0.0
**/
@:pure
public static function withFunction(text:String, viewFunction:() -> DisplayObject):TabItem {
var item = new TabItem();
item.text = text;
Expand All @@ -65,6 +67,7 @@ class TabItem {
@since 1.0.0
**/
@:pure
public static function withDisplayObject(text:String, viewInstance:DisplayObject):TabItem {
var item = new TabItem();
item.text = text;
Expand All @@ -78,6 +81,7 @@ class TabItem {
@since 1.3.0
**/
@:pure
public static function withFactory(text:String, viewFactory:AbstractDisplayObjectFactory<Dynamic, DisplayObject>):TabItem {
var item = new TabItem();
item.text = text;
Expand Down
1 change: 1 addition & 0 deletions src/feathers/utils/DPadFocusUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DPadFocusUtil {
@see feathers.layout.RelativePosition
**/
@:pure
public static function isBetterFocusForRelativePosition(object1:DisplayObject, object2:DisplayObject, focusedRect:Rectangle,
relativePosition:RelativePosition):Bool {
var rect:Rectangle = object1.getBounds(object1.stage);
Expand Down
2 changes: 2 additions & 0 deletions src/feathers/utils/DateUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class DateUtil {
@since 1.0.0
**/
@:pure
public static function getDaysInMonth(month:Int, ?year:Int):Int {
if (month == 1 && year != null && isLeapYear(year)) {
return FEBRUARY_NUMBER_OF_DAYS_LEAP_YEAR;
Expand All @@ -35,6 +36,7 @@ class DateUtil {
@since 1.0.0
**/
@:pure
public static function isLeapYear(year:Int):Bool {
if (year % 100 == 0) {
return year % 400 == 0;
Expand Down
2 changes: 2 additions & 0 deletions src/feathers/utils/DeviceUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class DeviceUtil {
@since 1.0.0
**/
@:pure
public static function isDesktop():Bool {
#if mobile
return false;
Expand All @@ -50,6 +51,7 @@ class DeviceUtil {
@since 1.0.0
**/
@:pure
public static function isMobile():Bool {
#if mobile
return true;
Expand Down
4 changes: 4 additions & 0 deletions src/feathers/utils/DisplayUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class DisplayUtil {
@since 1.0.0
**/
@:pure
public static function getDisplayObjectDepthFromStage(target:DisplayObject):Int {
if (target.stage == null) {
return -1;
Expand All @@ -46,6 +47,7 @@ class DisplayUtil {
@since 1.0.0
**/
@:pure
public static function getConcatenatedScaleX(target:DisplayObject):Float {
if (target == null) {
throw new ArgumentError("getConcatenatedScaleX target must not be null");
Expand All @@ -65,6 +67,7 @@ class DisplayUtil {
@since 1.0.0
**/
@:pure
public static function getConcatenatedScaleY(target:DisplayObject):Float {
if (target == null) {
throw new ArgumentError("getConcatenatedScaleY target must not be null");
Expand All @@ -84,6 +87,7 @@ class DisplayUtil {
@since 1.0.0
**/
@:pure
public static function getConcatenatedScale(target:DisplayObject, ?result:Point):Point {
if (target == null) {
throw new ArgumentError("getConcatenatedScale target must not be null");
Expand Down
1 change: 1 addition & 0 deletions src/feathers/utils/FocusUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import openfl.geom.Point;
@since 1.0.0
**/
class FocusUtil {
@:pure
public static function findAllFocusableObjects(target:DisplayObject, ?result:Array<IFocusObject>):Array<IFocusObject> {
if (result == null) {
result = [];
Expand Down
5 changes: 5 additions & 0 deletions src/feathers/utils/MathUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MathUtil {
@since 1.0.0
**/
@:pure
public static function roundDownToNearest(number:Float, nearest:Float = 1.0):Float {
if (nearest == 0) {
return number;
Expand All @@ -43,6 +44,7 @@ class MathUtil {
@since 1.0.0
**/
@:pure
public static function roundUpToNearest(number:Float, nearest:Float = 1.0):Float {
if (nearest == 0) {
return number;
Expand All @@ -65,6 +67,7 @@ class MathUtil {
@since 1.0.0
**/
@:pure
public static function roundToNearest(number:Float, nearest:Float = 1.0):Float {
if (nearest == 0) {
return number;
Expand All @@ -82,6 +85,7 @@ class MathUtil {
@since 1.0.0
**/
@:pure
public static function roundToPrecision(number:Float, precision:Int = 0):Float {
var decimalPlaces = Math.pow(10, precision);
return Math.fround(decimalPlaces * number) / decimalPlaces;
Expand All @@ -98,6 +102,7 @@ class MathUtil {
@param maxDifference the maximum difference between the two numbers to be considered equal
@return true if the numbers are considered equal
**/
@:pure
public static function fuzzyEquals(n1:Float, n2:Float, maxDifference:Float = 0.000001):Bool {
return Math.abs(n1 - n2) <= maxDifference;
}
Expand Down
1 change: 1 addition & 0 deletions src/feathers/utils/PopUpUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class PopUpUtil {
@since 1.0.0
**/
@:pure
public static function isTopLevelPopUpOrIsContainedByTopLevelPopUp(target:DisplayObject):Bool {
if (target.stage == null) {
return false;
Expand Down
4 changes: 4 additions & 0 deletions src/feathers/utils/ScaleUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ScaleUtil {
@since 1.0.0
**/
@:pure
public static function fitRectangle(original:Rectangle, into:Rectangle, ?result:Rectangle):Rectangle {
var width = original.width;
var height = original.height;
Expand All @@ -48,6 +49,7 @@ class ScaleUtil {
@since 1.0.0
**/
@:pure
public static function fillRectangle(original:Rectangle, into:Rectangle, ?result:Rectangle):Rectangle {
var width = original.width;
var height = original.height;
Expand All @@ -73,6 +75,7 @@ class ScaleUtil {
@since 1.0.0
**/
@:pure
public static function scaleToFit(originalWidth:Float, originalHeight:Float, targetWidth:Float, targetHeight:Float):Float {
var widthRatio = targetWidth / originalWidth;
var heightRatio = targetHeight / originalHeight;
Expand All @@ -89,6 +92,7 @@ class ScaleUtil {
@since 1.0.0
**/
@:pure
public static function scaleToFill(originalWidth:Float, originalHeight:Float, targetWidth:Float, targetHeight:Float):Float {
var widthRatio = targetWidth / originalWidth;
var heightRatio = targetHeight / originalHeight;
Expand Down
1 change: 1 addition & 0 deletions src/feathers/utils/TextFormatUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class TextFormatUtil {
@since 1.0.0
**/
@:pure
public static function clone(original:TextFormat):TextFormat {
var clone = new TextFormat(original.font, original.size, original.color, original.bold, original.italic, original.underline, original.url,
original.target, original.align, original.leftMargin, original.rightMargin, original.indent, original.leading);
Expand Down

0 comments on commit 963a4fb

Please sign in to comment.