Error with Dispatcher.BeginInvoke - asynchronous

I am trying to add an item to a sharepoint list but when i try to save my changes im getting this error with my Dispatcher.BeginInvoke 'Windows.UI.Core.CoreDispatcher' does not contain a definition for 'BeginInvoke' and no extension method 'BeginInvoke' accepting a first argument of type 'Windows.UI.Core.CoreDispatcher' could be found (are you missing a using directive or an assembly reference?
ctx.BeginSaveChanges(
(IAsyncResult result) => Dispatcher.BeginInvoke(
() => ctx.EndSaveChanges(result)),
ctx
);

Should use the following instead:
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => {
}

Related

Trying to decode an event using rescript-json-combinators

Trying to create an equivalent for decodeEvent using rescript-json-combinators. I couldn't figure out how to replace "Decoder(decoder)" since Decoders have been made abstract in rescript-json-combinators. Trying to use Decode.decode didn't work.
Any idea on how this could be solved?
let decodeEvent = (Decoder(decoder), value: Web_node.event) =>
try decoder(Obj.magic(value)) catch {
| ParseFail(e) => Error(e)
| _ => Error("Unknown JSON parsing error")
}
The purpose of decodeEvent seems to be two-fold:
To convert a Web_node.event to Json.t in order to use Json decoders on it.
To return a result instead of raising an exception on error.
The rescript-json-combinators API already has a result-based API. That's part of the reason why the implementation is now hidden and requires the use of Json.decode to run the decoders. That seems to be all that's missing here:
let decodeEvent = (decoder, value: Web_node.event) =>
value->Obj.magic->Json.decode(decoder)

I have some problems with "RTK Query"

recently I've just started to read RTK Query's document in the redux.js.org and understood the doc's main project doesn't show the Posts in CodeSandbox and just [object Object] is obvioused except of the Posts list which should being loaded by the fake server included in the default project .
secondly I couldn't managed the error in PostsList page (the Page which is included in the redux main project (simple social media)) .
features/posts/PostsList.js
export const PostList = () => {
const {
data: posts = [],
isSuccess,
isLoading,
isError,
error,
} = useGetPostsQuery()
const orderedPosts = useMemo(() => {
console.log(posts)
const ordered = posts.posts.slice()
ordered.sort((a, b) => b.date.localeCompare(a.date))
return ordered
}, [posts])
just got the [] as the posts value then this error appears "Cannot read properties of undefined (reading 'slice')"
and the whole the main project of redux is accessible right in this link
rtk-query-basics
I believe the problem is in the following line:
const ordered = posts.posts.slice()
It is trying to access a posts property on the posts array, which returns undefined (most likely a typo). This would explain the error message, as undefined is not an array, and therefore does not have a slice method.
To fix the problem, amend the line to look like this:
const ordered = posts.slice()

Dart won't compile because of unmatching types, 'List<T>' can't be assigned to the parameter type 'List<T> Function()'

The relevant part of the code looks like this:
static final Map<String, List<Provider>> _availableProviders = {};
Provider(this.name, this._requiresKey, this._versions) {
_versions.forEach((version) => {
Provider._availableProviders.putIfAbsent(version, <Provider>[]),
Provider._availableProviders[version].add(this)
});
}
_versions is a set of Strings and when I try and run I receive this error:
lib/src/api/Provider.dart:18:71: Error: The argument type 'List<Provider>' can't be assigned to the parameter type 'List<Provider> Function()'.
- 'List' is from 'dart:core'.
- 'Provider' is from 'package:bible/src/api/Provider.dart' ('lib/src/api/Provider.dart').
Provider._availableProviders.putIfAbsent(version, <Provider>[]),
The argument type 'List<Provider>' can't be assigned to the parameter type 'List<Provider> Function()'
I'm not exactly sure if this error has to do with the notation of the empty list I created or with how I instantiated the map. Any help would be appreciated!
Second parameter of Map's putIfAbsent is function, that returns value to be put, not value itself: https://api.dart.dev/stable/2.10.4/dart-core/Map/putIfAbsent.html
Rewrite your code to something like this:
static final Map<String, List<Provider>> _availableProviders = {};
Provider(this.name, this._requiresKey, this._versions) {
_versions.forEach((version) => {
Provider._availableProviders.putIfAbsent(version, () => <Provider>[]),
Provider._availableProviders[version].add(this)
});
}

exported typed functions that return functions should NOT require the returned function to be typed to work in other modules

For example if you are using redux-actions and have created the following module definition for it:
declare module 'redux-actions' {
declare type ActionType = string
declare type Action = {
type: ActionType,
payload?: any,
error?: bool,
meta?: any,
}
declare function createAction<T>(
type: string,
payloadCreator?: (...args: Array<T>) => any,
metaCreator?: Function
): (...args: Array<T>) => Action
}
and then you use that function to return a new function like this:
export const selectProfileTab = createAction('SELECT_PROFILE_TAB', (index: number) => {
playSound()
return { index }
})
and then in another file use it incorrectly like this:
selectorProfileTab('someString')
that won't report an error. It seems to be because flow requires annotations at the "boundaries" of modules. Am I correct?
Because the following does work:
export const selectProfileTab: (index: number) => any = createAction('SELECT_PROFILE_TAB', (index: number) => {
playSound()
return { index }
})
Notice I've annotated the returned function. The following will now produce an error:
selectProfileTab('someString')
I'm just trying to get a hold of this and verify this because it's a lot of extra "boilerplate" to annotate those returned functions, especially when it calling selectProfileTab('someString') would correctly produce an error if used in the same file. It makes you think: what's the point in creating module definitions for the redux-actions package which doesn't have them yet if it doesn't provide any/much value since you have to annotate your returned functions anyway. That's quite disappointing. Am I correct in determining that it's a module "boundaries" limitation/requirement with Flow? Are there any ways to get the desired result of not having to type returned functions that you export?

MVC5 combine db .Include with OrderBy

In my controller I'm including Balances and RZiS like this
Analysis1Full analysis1Full = db.Analysis1Full
.Include(u => u.Balance)
.Include(r => r.RZiS)
.SingleOrDefault(u => u.Analysis1FullId == id);
//enter code here
it gives me right object. The point is that I want to sort Balance by string filed (Year). But it gives me an error:
Analysis1Full analysis1Full = db.Analysis1Full
.Include(u => u.Balance.OrderBy(y => y.Year))
.Include(r => r.RZiS)
.SingleOrDefault(i => i.Analysis1FullId == id);
Error:
An exception of type 'System.ArgumentException' occurred in EntityFramework.dll but was not handled in user code
Additional information: The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.
The reason why the exception is thrown is simply because it is designed this way. According to MSDN, the Include() only Specifies the related objects to include in the query results.
To have the children in an order, you can add an OrderBy() when accessing them or you'd need to load them in a different query.
I solved it like this ... it is working
Analysis1Full analysis1Full = db.Analysis1Full.Find(id);
analysis1Full.Balance = db.Balances.Where(t=>t.Analysis1FullId == analysis1Full.Analysis1FullId).OrderBy(y=>y.Year).ToList();
analysis1Full.RZiS = db.RZiS.Where(t => t.Analysis1FullId == analysis1Full.Analysis1FullId).OrderBy(y => y.Year).ToList();
do you think it's good approach ?

Resources