Skip to content

Commit

Permalink
Merge pull request #1 from skclusive/develop
Browse files Browse the repository at this point in the history
5.0.0 from Develop
  • Loading branch information
skclusive authored Nov 10, 2020
2 parents 05079bd + 270f56b commit 87e2fc7
Show file tree
Hide file tree
Showing 23 changed files with 356 additions and 525 deletions.
60 changes: 26 additions & 34 deletions Skclusive.Mobx.Observable.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{97F1FFA7-2EA3-4793-B4C8-7E87B88BD6BC}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Observable", "src\Observable.csproj", "{41D1F6BA-85C8-4065-880B-2117BCC00C44}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Observable", "src\Observable\Observable.csproj", "{5F21699D-14FC-4A2D-9C05-E1FE6AE05AB8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{85D98476-E73E-4AC0-A3A0-BB9935E6B0C0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Observable.Tests", "test\Observable.Tests\Observable.Tests.csproj", "{D26EBFD2-EBD7-4A84-88DD-CE88945E8F44}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Observable.Tests", "test\Observable.Tests.csproj", "{583F047A-E657-47E5-AC70-A73BD4BC19DC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -24,33 +20,29 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5F21699D-14FC-4A2D-9C05-E1FE6AE05AB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5F21699D-14FC-4A2D-9C05-E1FE6AE05AB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F21699D-14FC-4A2D-9C05-E1FE6AE05AB8}.Debug|x64.ActiveCfg = Debug|Any CPU
{5F21699D-14FC-4A2D-9C05-E1FE6AE05AB8}.Debug|x64.Build.0 = Debug|Any CPU
{5F21699D-14FC-4A2D-9C05-E1FE6AE05AB8}.Debug|x86.ActiveCfg = Debug|Any CPU
{5F21699D-14FC-4A2D-9C05-E1FE6AE05AB8}.Debug|x86.Build.0 = Debug|Any CPU
{5F21699D-14FC-4A2D-9C05-E1FE6AE05AB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F21699D-14FC-4A2D-9C05-E1FE6AE05AB8}.Release|Any CPU.Build.0 = Release|Any CPU
{5F21699D-14FC-4A2D-9C05-E1FE6AE05AB8}.Release|x64.ActiveCfg = Release|Any CPU
{5F21699D-14FC-4A2D-9C05-E1FE6AE05AB8}.Release|x64.Build.0 = Release|Any CPU
{5F21699D-14FC-4A2D-9C05-E1FE6AE05AB8}.Release|x86.ActiveCfg = Release|Any CPU
{5F21699D-14FC-4A2D-9C05-E1FE6AE05AB8}.Release|x86.Build.0 = Release|Any CPU
{D26EBFD2-EBD7-4A84-88DD-CE88945E8F44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D26EBFD2-EBD7-4A84-88DD-CE88945E8F44}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D26EBFD2-EBD7-4A84-88DD-CE88945E8F44}.Debug|x64.ActiveCfg = Debug|Any CPU
{D26EBFD2-EBD7-4A84-88DD-CE88945E8F44}.Debug|x64.Build.0 = Debug|Any CPU
{D26EBFD2-EBD7-4A84-88DD-CE88945E8F44}.Debug|x86.ActiveCfg = Debug|Any CPU
{D26EBFD2-EBD7-4A84-88DD-CE88945E8F44}.Debug|x86.Build.0 = Debug|Any CPU
{D26EBFD2-EBD7-4A84-88DD-CE88945E8F44}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D26EBFD2-EBD7-4A84-88DD-CE88945E8F44}.Release|Any CPU.Build.0 = Release|Any CPU
{D26EBFD2-EBD7-4A84-88DD-CE88945E8F44}.Release|x64.ActiveCfg = Release|Any CPU
{D26EBFD2-EBD7-4A84-88DD-CE88945E8F44}.Release|x64.Build.0 = Release|Any CPU
{D26EBFD2-EBD7-4A84-88DD-CE88945E8F44}.Release|x86.ActiveCfg = Release|Any CPU
{D26EBFD2-EBD7-4A84-88DD-CE88945E8F44}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5F21699D-14FC-4A2D-9C05-E1FE6AE05AB8} = {97F1FFA7-2EA3-4793-B4C8-7E87B88BD6BC}
{D26EBFD2-EBD7-4A84-88DD-CE88945E8F44} = {85D98476-E73E-4AC0-A3A0-BB9935E6B0C0}
{41D1F6BA-85C8-4065-880B-2117BCC00C44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{41D1F6BA-85C8-4065-880B-2117BCC00C44}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41D1F6BA-85C8-4065-880B-2117BCC00C44}.Debug|x64.ActiveCfg = Debug|Any CPU
{41D1F6BA-85C8-4065-880B-2117BCC00C44}.Debug|x64.Build.0 = Debug|Any CPU
{41D1F6BA-85C8-4065-880B-2117BCC00C44}.Debug|x86.ActiveCfg = Debug|Any CPU
{41D1F6BA-85C8-4065-880B-2117BCC00C44}.Debug|x86.Build.0 = Debug|Any CPU
{41D1F6BA-85C8-4065-880B-2117BCC00C44}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41D1F6BA-85C8-4065-880B-2117BCC00C44}.Release|Any CPU.Build.0 = Release|Any CPU
{41D1F6BA-85C8-4065-880B-2117BCC00C44}.Release|x64.ActiveCfg = Release|Any CPU
{41D1F6BA-85C8-4065-880B-2117BCC00C44}.Release|x64.Build.0 = Release|Any CPU
{41D1F6BA-85C8-4065-880B-2117BCC00C44}.Release|x86.ActiveCfg = Release|Any CPU
{41D1F6BA-85C8-4065-880B-2117BCC00C44}.Release|x86.Build.0 = Release|Any CPU
{583F047A-E657-47E5-AC70-A73BD4BC19DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{583F047A-E657-47E5-AC70-A73BD4BC19DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{583F047A-E657-47E5-AC70-A73BD4BC19DC}.Debug|x64.ActiveCfg = Debug|Any CPU
{583F047A-E657-47E5-AC70-A73BD4BC19DC}.Debug|x64.Build.0 = Debug|Any CPU
{583F047A-E657-47E5-AC70-A73BD4BC19DC}.Debug|x86.ActiveCfg = Debug|Any CPU
{583F047A-E657-47E5-AC70-A73BD4BC19DC}.Debug|x86.Build.0 = Debug|Any CPU
{583F047A-E657-47E5-AC70-A73BD4BC19DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{583F047A-E657-47E5-AC70-A73BD4BC19DC}.Release|Any CPU.Build.0 = Release|Any CPU
{583F047A-E657-47E5-AC70-A73BD4BC19DC}.Release|x64.ActiveCfg = Release|Any CPU
{583F047A-E657-47E5-AC70-A73BD4BC19DC}.Release|x64.Build.0 = Release|Any CPU
{583F047A-E657-47E5-AC70-A73BD4BC19DC}.Release|x86.ActiveCfg = Release|Any CPU
{583F047A-E657-47E5-AC70-A73BD4BC19DC}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
12 changes: 10 additions & 2 deletions src/Observable/Observable.csproj → src/Observable.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>2.0.0</VersionPrefix>
<VersionPrefix>5.0.0</VersionPrefix>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<AssemblyName>Skclusive.Mobx.Observable</AssemblyName>
<PackageId>Skclusive.Mobx.Observable</PackageId>
<RootNamespace>Skclusive.Mobx.Observable</RootNamespace>
<Authors>Skclusive</Authors>
<Company>Skclusive</Company>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Skclusive.Core.Collection" Version="5.0.0" />
</ItemGroup>
<!-- <ItemGroup>
<ProjectReference Include="..\..\Skclusive.Core.Collection\src\Collection.csproj" Version="5.0.0" />
</ItemGroup> -->

</Project>
40 changes: 37 additions & 3 deletions src/Observable/Builder/TypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@

namespace Skclusive.Mobx.Observable
{
public class VolatileProperty
{
public string Name { set; get; }

public Type Type { set; get; }

public object Default { set; get; }
}

public class ObservableProperty
{
public string Name { set; get; }
Expand Down Expand Up @@ -32,18 +41,25 @@ public class ActionMethod

public class ObservableTypeDef
{
public ObservableTypeDef(IEnumerable<ObservableProperty> observables,
IEnumerable<ComputedProperty> computeds, IEnumerable<ActionMethod> actions = null)
public ObservableTypeDef(
IEnumerable<ObservableProperty> observables,
IEnumerable<VolatileProperty> volatiles,
IEnumerable<ComputedProperty> computeds,
IEnumerable<ActionMethod> actions = null)
{
Observables = observables;

Volatiles = volatiles;

Computeds = computeds;

Actions = actions ?? Enumerable.Empty<ActionMethod>();
}

public IEnumerable<ObservableProperty> Observables { private set; get; }

public IEnumerable<VolatileProperty> Volatiles { private set; get; }

public IEnumerable<ComputedProperty> Computeds { private set; get; }

public IEnumerable<ActionMethod> Actions { private set; get; }
Expand All @@ -53,6 +69,8 @@ public class ObservableTypeDefBuilder<T>
{
private readonly ISet<ObservableProperty> ObservableProperties = new HashSet<ObservableProperty>();

private readonly ISet<VolatileProperty> VolatileProperties = new HashSet<VolatileProperty>();

private readonly ISet<ComputedProperty> ComputedProperties = new HashSet<ComputedProperty>();

private readonly ISet<ActionMethod> ActionMethods = new HashSet<ActionMethod>();
Expand All @@ -73,6 +91,22 @@ public class ObservableTypeDefBuilder<T>
return this;
}

public ObservableTypeDefBuilder<T> Volatile<I>(Expression<Func<T, I>> expresion, I defaultValue = default(I))
{
var property = ExpressionUtils.GetPropertySymbol(expresion);

VolatileProperties.Add(new VolatileProperty
{
Name = property,

Default = defaultValue,

Type = typeof(I)
});

return this;
}

public ObservableTypeDefBuilder<T> Computed<I>(Expression<Func<T, I>> expresion, Func<T, I> compute)
{
var property = ExpressionUtils.GetPropertySymbol<T, I>(expresion);
Expand Down Expand Up @@ -163,7 +197,7 @@ public ObservableTypeDefBuilder<T> Action<A1, A2, A3, A4>(Expression<Action<T>>

public ObservableTypeDef Build()
{
return new ObservableTypeDef(ObservableProperties, ComputedProperties, ActionMethods);
return new ObservableTypeDef(ObservableProperties, VolatileProperties, ComputedProperties, ActionMethods);
}
}
}
56 changes: 0 additions & 56 deletions src/Observable/Concretes/Map.cs

This file was deleted.

37 changes: 32 additions & 5 deletions src/Observable/Concretes/ObservableList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public class ObservableList<TIn, TOut> : IObservableList<TIn, TOut>, IDepTreeNod

public IList<Action<IListDidChange<TIn>>> Listeners { private set; get; } = new List<Action<IListDidChange<TIn>>>();

protected ObservableList(string name, IManipulator<TIn, TOut> manipulator = null)
public object Meta { get; }

protected ObservableList(string name, IManipulator<TIn, TOut> manipulator = null, object meta = null)
{
Values = new List<TIn>();

Expand All @@ -34,11 +36,13 @@ protected ObservableList(string name, IManipulator<TIn, TOut> manipulator = null
Manipulator = manipulator ?? Manipulator<TIn, TOut>.For();

KeysAtom = new Atom(Name);

Meta = meta;
}

public static IObservableList<TIn, TOut> From(IEnumerable<TOut> values = null, string name = null, IManipulator<TIn, TOut> manipulator = null)
public static IObservableList<TIn, TOut> From(IEnumerable<TOut> values = null, string name = null, IManipulator<TIn, TOut> manipulator = null, object meta = null)
{
var list = new ObservableList<TIn, TOut>(name, manipulator);
var list = new ObservableList<TIn, TOut>(name, manipulator, meta);

if (values != null)
{
Expand All @@ -52,6 +56,22 @@ public static IObservableList<TIn, TOut> From(IEnumerable<TOut> values = null, s
return list;
}

public static IObservableList<TIn, TOut> FromIn(IEnumerable<TIn> values = null, string name = null, IManipulator<TIn, TOut> manipulator = null, object meta = null)
{
var list = new ObservableList<TIn, TOut>(name, manipulator, meta);

if (values != null)
{
var previous = Actions.AllowStateChangesStart(true);

list.SpliceWithIn(0, 0, values.ToArray());

Actions.AllowStateChangesEnd(previous);
}

return list;
}

public TOut this[int key]
{
get
Expand Down Expand Up @@ -116,6 +136,13 @@ public void Insert(int index, TOut value)
Splice(index, 0, value);
}

public int FindIndex(Predicate<TOut> match)
{
KeysAtom.ReportObserved();

return Dehance(Values).ToList().FindIndex(match);
}

public void Unshift(TOut value)
{
Insert(0, value);
Expand Down Expand Up @@ -286,7 +313,7 @@ protected TOut[] SpliceWith(int? argIndex, int? argDeleteCount, params TOut[] ne
return SpliceWithIn(argIndex, argDeleteCount, newItems.Select(newItem => Manipulator.Enhance(newItem)).ToArray());
}

private TOut[] SpliceWithIn(int? argIndex, int? argDeleteCount, params TIn[] newItems)
protected TOut[] SpliceWithIn(int? argIndex, int? argDeleteCount, params TIn[] newItems)
{
KeysAtom.CheckIfStateModificationsAreAllowed();

Expand All @@ -312,7 +339,7 @@ private TOut[] SpliceWithIn(int? argIndex, int? argDeleteCount, params TIn[] new
var change = this.NotifyInterceptors<IListWillChange<TIn>>(ListWillChange<TIn>.Splice(this, index, newItems, deleteCount));
if (change == null)
{
return new TOut[] { };
return Array.Empty<TOut>();
}
deleteCount = change.RemovedCount;
newItems = change.Added;
Expand Down
Loading

0 comments on commit 87e2fc7

Please sign in to comment.