@bara/core
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -6,2 +6,24 @@ # Change Log | ||
# [2.3.0](https://github.com/barajs/bara/compare/v2.2.0...v2.3.0) (2019-04-19) | ||
### Bug Fixes | ||
* **core:** prevent duplicate stream registration ([9d01ca5](https://github.com/barajs/bara/commit/9d01ca5)) | ||
* **core:** trigger is not map to triggerRegistry ([00e01eb](https://github.com/barajs/bara/commit/00e01eb)) | ||
* **core:** WIP on duplicate stream ([d95ffb9](https://github.com/barajs/bara/commit/d95ffb9)) | ||
### Features | ||
* **barn:** new operator `setBarnState` based on `useEmitter` ([d4a2bd0](https://github.com/barajs/bara/commit/d4a2bd0)), closes [#35](https://github.com/barajs/bara/issues/35) | ||
* **core:** add setupEmitter ([f31f547](https://github.com/barajs/bara/commit/f31f547)) | ||
* **core:** complete `createEmitter` with `useEmitter` hook ([8d85655](https://github.com/barajs/bara/commit/8d85655)), closes [#35](https://github.com/barajs/bara/issues/35) | ||
* **core:** export all from xstream ([07bd747](https://github.com/barajs/bara/commit/07bd747)) | ||
* **core:** WIP on adding useEmitter ([59f62d3](https://github.com/barajs/bara/commit/59f62d3)) | ||
# [2.2.0](https://github.com/barajs/bara/compare/v2.1.0...v2.2.0) (2019-04-10) | ||
@@ -8,0 +30,0 @@ |
@@ -0,3 +1,5 @@ | ||
import { Stream } from 'xstream'; | ||
import { BaraNormalActionConfig } from './model/action'; | ||
import { BaraConditionConfig } from './model/condition'; | ||
import { BaraEmitterMap, BaraEmitterSetup } from './model/emitter'; | ||
import { EventType } from './model/event'; | ||
@@ -7,5 +9,7 @@ import { BaraStreamSetup } from './model/stream'; | ||
declare const register: (app: () => void) => { | ||
appStream: Stream<import("./model/stream").BaraStreamPayload<any>>; | ||
emitterMap: BaraEmitterMap; | ||
streamRegistry: any[]; | ||
triggerRegistry: any[]; | ||
}, useStream: <T>(streamSetup: BaraStreamSetup<T>) => any, useTrigger: <T>(setup: BaraTriggerSetup<T>) => any, useEvent: <T>(eventType: EventType) => import("./hooks/use-event").UseEventHookType<T>, useCustomEvent: <T>(eventType: EventType, customFilter: (...args: any[]) => boolean) => import("./hooks/use-event").UseEventHookType<T>, useAction: <T>(callback: BaraNormalActionConfig<T>) => import("./hooks/use-action").UseActionHookType<T>, useCondition: <T>(config: BaraConditionConfig<T>) => import("./hooks/use-condition").UseConditionHookType<T>; | ||
export { register, useStream, useTrigger, useEvent, useCustomEvent, useAction, useCondition, }; | ||
}, useStream: <T>(streamSetup: BaraStreamSetup<T>) => any, useTrigger: <T>(setup: BaraTriggerSetup<T>) => any, useEvent: <T>(eventType: EventType) => import("./hooks/use-event").UseEventHookType<T>, useCustomEvent: <T>(eventType: EventType, customFilter: (...args: any[]) => boolean) => import("./hooks/use-event").UseEventHookType<T>, useAction: <T>(callback: BaraNormalActionConfig<T>) => import("./hooks/use-action").UseActionHookType<T>, useCondition: <T>(config: BaraConditionConfig<T>) => import("./hooks/use-condition").UseConditionHookType<T>, useEmitter: <T>(eventType: EventType) => ((...args: any[]) => void) | null, createEmitter: <T>(setup: BaraEmitterSetup<T>) => any; | ||
export { register, useStream, useTrigger, useEvent, useCustomEvent, useAction, useCondition, useEmitter, createEmitter, }; |
@@ -7,2 +7,3 @@ "use strict"; | ||
const xstream_1 = __importDefault(require("xstream")); | ||
const emitter_1 = require("./emitter"); | ||
const string_1 = require("./helpers/string"); | ||
@@ -18,2 +19,3 @@ const trigger_1 = require("./model/trigger"); | ||
let appStream = xstream_1.default.never(); | ||
let emitStream = xstream_1.default.never(); | ||
// Handle hook Stream registry | ||
@@ -27,16 +29,32 @@ const streamRegistry = []; | ||
let triggerConfigIndex = 0; | ||
// Handle Emitter registry | ||
const emitterRegistry = []; | ||
let emitterRegistryIndex = 0; | ||
const emitterMap = {}; // Use JS Object for fast access via key | ||
return { | ||
register(app) { | ||
app(); | ||
return { streamRegistry, triggerRegistry }; | ||
return { appStream, emitterMap, streamRegistry, triggerRegistry }; | ||
}, | ||
useStream(streamSetup) { | ||
streamRegistry[streamRegistryIndex] = | ||
streamRegistry[streamRegistryIndex] || | ||
use_stream_1.useStreamHook(streamSetup, streamRegistryIndex); | ||
// Merge new stream to the main app stream to make global stream | ||
appStream = xstream_1.default.merge(appStream, streamRegistry[streamRegistryIndex] | ||
._$); | ||
streamRegistryIndex = streamRegistryIndex + 1; | ||
return streamRegistry[streamRegistryIndex - 1]; | ||
let stream; | ||
let duplicateIndex = -1; | ||
if (!streamRegistry[streamRegistryIndex]) { | ||
const newStream = use_stream_1.useStreamHook(streamSetup, streamRegistryIndex); | ||
// Check stream dupplicated | ||
duplicateIndex = streamRegistry.findIndex(s => s && s.name === newStream.name); | ||
stream = | ||
duplicateIndex > -1 ? streamRegistry[duplicateIndex] : newStream; | ||
} | ||
else { | ||
stream = streamRegistry[streamRegistryIndex]; | ||
} | ||
if (duplicateIndex === -1) { | ||
streamRegistry[streamRegistryIndex] = stream; | ||
// Merge new stream to the main app stream to make global stream | ||
appStream = xstream_1.default.merge(appStream, streamRegistry[streamRegistryIndex] | ||
._$); | ||
streamRegistryIndex = streamRegistryIndex + 1; | ||
} | ||
return streamRegistry[duplicateIndex > -1 ? duplicateIndex : streamRegistryIndex - 1]; | ||
}, | ||
@@ -55,4 +73,6 @@ useTrigger(setup) { | ||
// Setup real trigger | ||
const currentTrigger = triggerRegistry[triggerRegistryIndex] || | ||
use_trigger_1.useTriggerHook(config, triggerRegistryIndex); | ||
triggerRegistry[triggerRegistryIndex] = | ||
triggerRegistry[triggerRegistryIndex] || | ||
use_trigger_1.useTriggerHook(config, triggerRegistryIndex); | ||
const currentTrigger = triggerRegistry[triggerRegistryIndex]; | ||
// Attach BaraEvent, BaraCondition, BaraAction with current BaraTrigger | ||
@@ -92,5 +112,28 @@ const event = currentTrigger.attach(trigger_1.TriggerEntityType.EVENT, eventSetup, [ | ||
}, | ||
createEmitter(setup) { | ||
emitterRegistry[emitterRegistryIndex] = | ||
emitterRegistry[emitterRegistryIndex] || | ||
emitter_1.createEmitterHook(setup, emitterRegistryIndex); | ||
// Merge new stream to the main app stream to make global stream | ||
emitStream = xstream_1.default.merge(emitStream, emitterRegistry[emitterRegistryIndex] | ||
._$); | ||
// Assign emitter function to emitterMap for fast access | ||
let i = emitterRegistry[emitterRegistryIndex].emitFuncs.length; | ||
// tslint:disable-next-line | ||
while (i--) { | ||
const [eventType, emitFunc] = emitterRegistry[emitterRegistryIndex].emitFuncs[i]; | ||
emitterMap[eventType] = emitFunc; | ||
} | ||
emitterRegistryIndex += 1; | ||
return emitterRegistry[emitterRegistryIndex - 1]; | ||
}, | ||
useEmitter(eventType) { | ||
if (eventType() in emitterMap) { | ||
return emitterMap[eventType()]; | ||
} | ||
return null; | ||
}, | ||
}; | ||
})(); | ||
const { register, useStream, useTrigger, useEvent, useCustomEvent, useAction, useCondition, } = bara; | ||
const { register, useStream, useTrigger, useEvent, useCustomEvent, useAction, useCondition, useEmitter, createEmitter, } = bara; | ||
exports.register = register; | ||
@@ -103,2 +146,4 @@ exports.useStream = useStream; | ||
exports.useCondition = useCondition; | ||
exports.useEmitter = useEmitter; | ||
exports.createEmitter = createEmitter; | ||
//# sourceMappingURL=bara.js.map |
@@ -57,3 +57,3 @@ "use strict"; | ||
}; | ||
const _$ = config.memory | ||
const _$ = config.memory === true | ||
? xstream_1.default.createWithMemory(producer) | ||
@@ -60,0 +60,0 @@ : xstream_1.default.create(producer); |
export * from './bara'; | ||
export * from './event'; | ||
export * from './model'; | ||
export * from './emitter'; | ||
export * from './xstream'; |
@@ -9,2 +9,4 @@ "use strict"; | ||
__export(require("./model")); | ||
__export(require("./emitter")); | ||
__export(require("./xstream")); | ||
//# sourceMappingURL=index.js.map |
export * from './action'; | ||
export * from './app'; | ||
export * from './base'; | ||
export * from './condition'; | ||
export * from './event'; | ||
export * from './emitter'; | ||
export * from './stream'; | ||
export * from './trigger'; |
@@ -27,8 +27,1 @@ import { MemoryStream, Stream } from 'xstream'; | ||
} | ||
export interface SetupCallbacks<T> { | ||
emit: (eventType: EventType, payload: T) => void; | ||
emitCallback?: (eventType: EventType, payload: T, callback: (...args: any) => void) => void; | ||
error?: (errorMessage: string) => void; | ||
done?: () => void; | ||
options?: any; | ||
} |
{ | ||
"name": "@bara/core", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "BaraJS Core - Created For Creating", | ||
@@ -29,13 +29,13 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@types/jest": "24.0.6", | ||
"@types/jest": "24.0.11", | ||
"concurrently": "4.1.0", | ||
"jest": "24.1.0", | ||
"jest": "24.7.1", | ||
"npm-watch": "0.6.0", | ||
"prettier": "1.16.4", | ||
"ts-jest": "24.0.0", | ||
"tslint": "5.15.0", | ||
"prettier": "1.17.0", | ||
"ts-jest": "24.0.2", | ||
"tslint": "5.16.0", | ||
"tslint-config-airbnb": "5.11.1", | ||
"tslint-config-prettier": "1.18.0", | ||
"tslint-react": "4.0.0", | ||
"typescript": "~3.1.0" | ||
"typescript": "3.4.4" | ||
}, | ||
@@ -45,3 +45,3 @@ "dependencies": { | ||
}, | ||
"gitHead": "665cdc1a7688979de1e696917c6a3c28d337e8de" | ||
"gitHead": "e343d9c27b3ee9a195b3d0c550648301a3e88232" | ||
} |
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
Sorry, the diff of this file is not supported yet
55884
70
732