Beispiel #1
0
 internal void Dispatch(string json)
 {
     if (!string.IsNullOrWhiteSpace(json))
     {
         var actions = JArray.Parse(json);
         logState = LogReducer.Reduce(logState, actions);
         OnChange?.Invoke(logState);
     }
 }
Beispiel #2
0
        public static LogState Reduce(LogState state, JArray actions)
        {
            var logs = state.Logs.Clone();

            foreach (JObject action in actions)
            {
                logs.Patch(action.ToObject <Patch>());
            }

            return(LogState.WithLogs(logs));
        }
Beispiel #3
0
        /// <summary>
        /// Select all the logs in the store
        /// </summary>
        /// <param name="logState"></param>
        /// <returns>An ImmutableArray of LogLines</returns>
        public static ImmutableArray <LogLine> SelectAllLogs(this LogState logState)
        {
            var lines = logState.Logs.GetAt <JObject>("line") ?? new JObject();
            var logs  = new List <LogLine>();

            foreach (var log in lines)
            {
                logs.Add(log.Value.ToObject <LogLine>());
            }

            return(logs.ToImmutableArray());
        }
Beispiel #4
0
        /// <summary>
        /// Select all the logs since a given line number
        /// </summary>
        /// <param name="logState"></param>
        /// <returns>An ImmutableArray of LogLines</returns>
        public static ImmutableArray <LogLine> SelectLogsSince(this LogState logState, int lineNumber)
        {
            var lines = logState.Logs.GetAt <JObject>("line") ?? new JObject();
            var logs  = new List <LogLine>();

            for (var i = lineNumber; i < lines.Count; i++)
            {
                var log = logState.Logs.GetAt <LogLine>($"line.{i}");;
                if (log != null)
                {
                    logs.Add(log);
                }
            }

            return(logs.ToImmutableArray());
        }
Beispiel #5
0
 internal LogStore()
 {
     logState = LogState.WithLogs(new PatchDocument());
 }