piral-feeds
Advanced tools
Comparing version 0.10.0-pre.837 to 0.10.0-pre.838
@@ -1,8 +0,7 @@ | ||
import { Atom } from '@dbeining/react-atom'; | ||
import { GlobalState } from 'piral-core'; | ||
import { GlobalStateContext } from 'piral-core'; | ||
import { ConnectorDetails, FeedReducer } from './types'; | ||
export declare function createFeed(ctx: Atom<GlobalState>, id: string): void; | ||
export declare function destroyFeed(ctx: Atom<GlobalState>, id: string): void; | ||
export declare function loadFeed<TData, TItem>(ctx: Atom<GlobalState>, options: ConnectorDetails<TData, TItem>): Promise<void>; | ||
export declare function loadedFeed(ctx: Atom<GlobalState>, id: string, data: any, error: any): void; | ||
export declare function updateFeed<TData, TItem>(ctx: Atom<GlobalState>, id: string, item: TItem, reducer: FeedReducer<TData, TItem>): Promise<void>; | ||
export declare function createFeed(ctx: GlobalStateContext, id: string): void; | ||
export declare function destroyFeed(ctx: GlobalStateContext, id: string): void; | ||
export declare function loadFeed<TData, TItem>(ctx: GlobalStateContext, options: ConnectorDetails<TData, TItem>): Promise<void>; | ||
export declare function loadedFeed(ctx: GlobalStateContext, id: string, data: any, error: any): void; | ||
export declare function updateFeed<TData, TItem>(ctx: GlobalStateContext, id: string, item: TItem, reducer: FeedReducer<TData, TItem>): Promise<void>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const react_atom_1 = require("@dbeining/react-atom"); | ||
const piral_core_1 = require("piral-core"); | ||
function createFeed(ctx, id) { | ||
react_atom_1.swap(ctx, state => (Object.assign(Object.assign({}, state), { feeds: piral_core_1.withKey(state.feeds, id, { | ||
ctx.dispatch(state => (Object.assign(Object.assign({}, state), { feeds: piral_core_1.withKey(state.feeds, id, { | ||
data: undefined, | ||
@@ -15,3 +14,3 @@ error: undefined, | ||
function destroyFeed(ctx, id) { | ||
react_atom_1.swap(ctx, state => (Object.assign(Object.assign({}, state), { feeds: piral_core_1.withoutKey(state.feeds, id) }))); | ||
ctx.dispatch(state => (Object.assign(Object.assign({}, state), { feeds: piral_core_1.withoutKey(state.feeds, id) }))); | ||
} | ||
@@ -21,3 +20,3 @@ exports.destroyFeed = destroyFeed; | ||
const { id } = options; | ||
react_atom_1.swap(ctx, state => (Object.assign(Object.assign({}, state), { feeds: piral_core_1.withKey(state.feeds, id, { | ||
ctx.dispatch(state => (Object.assign(Object.assign({}, state), { feeds: piral_core_1.withKey(state.feeds, id, { | ||
data: undefined, | ||
@@ -37,3 +36,3 @@ error: undefined, | ||
function loadedFeed(ctx, id, data, error) { | ||
react_atom_1.swap(ctx, state => (Object.assign(Object.assign({}, state), { feeds: piral_core_1.withKey(state.feeds, id, { | ||
ctx.dispatch(state => (Object.assign(Object.assign({}, state), { feeds: piral_core_1.withKey(state.feeds, id, { | ||
loading: false, | ||
@@ -47,3 +46,3 @@ loaded: true, | ||
function updateFeed(ctx, id, item, reducer) { | ||
const feed = react_atom_1.deref(ctx).feeds[id]; | ||
const feed = ctx.readState(state => state.feeds[id]); | ||
const result = reducer(feed.data, item); | ||
@@ -50,0 +49,0 @@ if (result instanceof Promise) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const actions = require("./actions"); | ||
const react_atom_1 = require("@dbeining/react-atom"); | ||
const piral_core_1 = require("piral-core"); | ||
@@ -14,3 +13,3 @@ const withFeed_1 = require("./withFeed"); | ||
context.defineActions(actions); | ||
react_atom_1.swap(context.state, state => (Object.assign(Object.assign({}, state), { feeds: {} }))); | ||
context.dispatch(state => (Object.assign(Object.assign({}, state), { feeds: {} }))); | ||
return (_, target) => { | ||
@@ -17,0 +16,0 @@ let feeds = 0; |
{ | ||
"name": "piral-feeds", | ||
"version": "0.10.0-pre.837", | ||
"version": "0.10.0-pre.838", | ||
"description": "Plugin for connecting data feeds in Piral.", | ||
@@ -39,3 +39,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"piral-core": "^0.10.0-pre.837" | ||
"piral-core": "^0.10.0-pre.838" | ||
}, | ||
@@ -45,3 +45,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "5e8fd9a6f76c1505c459b18a5a06fcbeaa77f1a8" | ||
"gitHead": "5d2f55dafff3ceb751877958c5691dfbf995ae84" | ||
} |
import { Atom, deref } from '@dbeining/react-atom'; | ||
import { createActions, createListener } from 'piral-core'; | ||
import { destroyFeed, createFeed, loadedFeed, updateFeed, loadFeed } from './actions'; | ||
@@ -13,3 +14,4 @@ | ||
}); | ||
destroyFeed(state, 'foo'); | ||
const ctx = createActions(state, createListener({})); | ||
destroyFeed(ctx, 'foo'); | ||
expect(deref(state)).toEqual({ | ||
@@ -30,3 +32,4 @@ foo: 5, | ||
}); | ||
createFeed(state, 'bar'); | ||
const ctx = createActions(state, createListener({})); | ||
createFeed(ctx, 'bar'); | ||
expect(deref(state)).toEqual({ | ||
@@ -53,3 +56,4 @@ foo: 5, | ||
}); | ||
loadedFeed(state, 'bar', 'test', 'errror'); | ||
const ctx = createActions(state, createListener({})); | ||
loadedFeed(ctx, 'bar', 'test', 'errror'); | ||
expect(deref(state)).toEqual({ | ||
@@ -82,3 +86,4 @@ foo: 5, | ||
}); | ||
updateFeed(state, 'bar', 15, (data, item) => [...data, item]); | ||
const ctx = createActions(state, createListener({})); | ||
updateFeed(ctx, 'bar', 15, (data, item) => [...data, item]); | ||
expect(deref(state)).toEqual({ | ||
@@ -111,3 +116,4 @@ foo: 5, | ||
}); | ||
await updateFeed(state, 'bar', 15, (data, item) => Promise.resolve([...data, item])); | ||
const ctx = createActions(state, createListener({})); | ||
await updateFeed(ctx, 'bar', 15, (data, item) => Promise.resolve([...data, item])); | ||
expect(deref(state)).toEqual({ | ||
@@ -140,3 +146,4 @@ foo: 5, | ||
}); | ||
await updateFeed(state, 'bar', 15, (data, item) => Promise.reject('Failed')); | ||
const ctx = createActions(state, createListener({})); | ||
await updateFeed(ctx, 'bar', 15, () => Promise.reject('Failed')); | ||
expect(deref(state)).toEqual({ | ||
@@ -170,3 +177,4 @@ foo: 5, | ||
let cb = undefined; | ||
const promise = loadFeed(state, { | ||
const ctx = createActions(state, createListener({})); | ||
const promise = loadFeed(ctx, { | ||
id: 'bar', | ||
@@ -236,3 +244,4 @@ initialize() { | ||
}); | ||
await loadFeed(state, { | ||
const ctx = createActions(state, createListener({})); | ||
await loadFeed(ctx, { | ||
id: 'bar', | ||
@@ -239,0 +248,0 @@ initialize() { |
@@ -1,7 +0,6 @@ | ||
import { swap, Atom, deref } from '@dbeining/react-atom'; | ||
import { GlobalState, withKey, withoutKey } from 'piral-core'; | ||
import { withKey, withoutKey, GlobalStateContext } from 'piral-core'; | ||
import { ConnectorDetails, FeedReducer } from './types'; | ||
export function createFeed(ctx: Atom<GlobalState>, id: string) { | ||
swap(ctx, state => ({ | ||
export function createFeed(ctx: GlobalStateContext, id: string) { | ||
ctx.dispatch(state => ({ | ||
...state, | ||
@@ -17,4 +16,4 @@ feeds: withKey(state.feeds, id, { | ||
export function destroyFeed(ctx: Atom<GlobalState>, id: string) { | ||
swap(ctx, state => ({ | ||
export function destroyFeed(ctx: GlobalStateContext, id: string) { | ||
ctx.dispatch(state => ({ | ||
...state, | ||
@@ -25,6 +24,6 @@ feeds: withoutKey(state.feeds, id), | ||
export function loadFeed<TData, TItem>(ctx: Atom<GlobalState>, options: ConnectorDetails<TData, TItem>) { | ||
export function loadFeed<TData, TItem>(ctx: GlobalStateContext, options: ConnectorDetails<TData, TItem>) { | ||
const { id } = options; | ||
swap(ctx, state => ({ | ||
ctx.dispatch(state => ({ | ||
...state, | ||
@@ -51,4 +50,4 @@ feeds: withKey(state.feeds, id, { | ||
export function loadedFeed(ctx: Atom<GlobalState>, id: string, data: any, error: any) { | ||
swap(ctx, state => ({ | ||
export function loadedFeed(ctx: GlobalStateContext, id: string, data: any, error: any) { | ||
ctx.dispatch(state => ({ | ||
...state, | ||
@@ -65,3 +64,3 @@ feeds: withKey(state.feeds, id, { | ||
export function updateFeed<TData, TItem>( | ||
ctx: Atom<GlobalState>, | ||
ctx: GlobalStateContext, | ||
id: string, | ||
@@ -71,3 +70,3 @@ item: TItem, | ||
) { | ||
const feed = deref(ctx).feeds[id]; | ||
const feed = ctx.readState(state => state.feeds[id]); | ||
const result = reducer(feed.data, item); | ||
@@ -74,0 +73,0 @@ |
import * as actions from './actions'; | ||
import { swap } from '@dbeining/react-atom'; | ||
import { buildName, Extend } from 'piral-core'; | ||
@@ -20,3 +19,3 @@ import { withFeed } from './withFeed'; | ||
swap(context.state, state => ({ | ||
context.dispatch(state => ({ | ||
...state, | ||
@@ -23,0 +22,0 @@ feeds: {}, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46785
1215